Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_scale_map.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_scale_map.cpp
r4271 r8127 9 9 10 10 #include "qwt_scale_map.h" 11 #include "qwt_math.h" 11 12 #include <qrect.h> 12 #include <qalgorithms.h>13 #include <qmath.h>14 13 #include <qdebug.h> 15 16 #if QT_VERSION < 0x04060117 #define qExp(x) ::exp(x)18 #endif19 20 //! Smallest allowed value for logarithmic scales: 1.0e-15021 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMin = 1.0e-150;22 23 //! Largest allowed value for logarithmic scales: 1.0e15024 QT_STATIC_CONST_IMPL double QwtScaleMap::LogMax = 1.0e150;25 26 //! Constructor for a linear transformation27 QwtScaleTransformation::QwtScaleTransformation( Type type ):28 d_type( type )29 {30 }31 32 //! Destructor33 QwtScaleTransformation::~QwtScaleTransformation()34 {35 }36 37 //! Create a clone of the transformation38 QwtScaleTransformation *QwtScaleTransformation::copy() const39 {40 return new QwtScaleTransformation( d_type );41 }42 43 /*!44 \brief Transform a value from the coordinate system of a scale45 into the coordinate system of the paint device46 47 \param s Value related to the coordinate system of the scale48 \param s1 First border of the coordinate system of the scale49 \param s2 Second border of the coordinate system of the scale50 \param p1 First border of the coordinate system of the paint device51 \param p2 Second border of the coordinate system of the paint device52 \return53 <dl>54 <dt>linear mapping:<dd>p1 + (p2 - p1) / (s2 - s1) * (s - s1);</dd>55 </dl>56 <dl>57 <dt>log10 mapping: <dd>p1 + (p2 - p1) / log(s2 / s1) * log(s / s1);</dd>58 </dl>59 */60 61 double QwtScaleTransformation::xForm(62 double s, double s1, double s2, double p1, double p2 ) const63 {64 if ( d_type == Log10 )65 return p1 + ( p2 - p1 ) / log( s2 / s1 ) * log( s / s1 );66 else67 return p1 + ( p2 - p1 ) / ( s2 - s1 ) * ( s - s1 );68 }69 70 /*!71 \brief Transform a value from the coordinate system of the paint device72 into the coordinate system of a scale.73 74 \param p Value related to the coordinate system of the paint device75 \param p1 First border of the coordinate system of the paint device76 \param p2 Second border of the coordinate system of the paint device77 \param s1 First border of the coordinate system of the scale78 \param s2 Second border of the coordinate system of the scale79 \return80 <dl>81 <dt>linear mapping:<dd>s1 + ( s2 - s1 ) / ( p2 - p1 ) * ( p - p1 );</dd>82 </dl>83 <dl>84 <dt>log10 mapping:<dd>exp((p - p1) / (p2 - p1) * log(s2 / s1)) * s1;</dd>85 </dl>86 */87 88 double QwtScaleTransformation::invXForm( double p, double p1, double p2,89 double s1, double s2 ) const90 {91 if ( d_type == Log10 )92 return qExp( ( p - p1 ) / ( p2 - p1 ) * log( s2 / s1 ) ) * s1;93 else94 return s1 + ( s2 - s1 ) / ( p2 - p1 ) * ( p - p1 );95 }96 14 97 15 /*! … … 105 23 d_p1( 0.0 ), 106 24 d_p2( 1.0 ), 107 d_cnv( 1.0 ) 108 { 109 d_transform ation = new QwtScaleTransformation(110 QwtScaleTransformation::Linear ); 25 d_cnv( 1.0 ), 26 d_ts1( 0.0 ), 27 d_transform( NULL ) 28 { 111 29 } 112 30 … … 117 35 d_p1( other.d_p1 ), 118 36 d_p2( other.d_p2 ), 119 d_cnv( other.d_cnv ) 120 { 121 d_transformation = other.d_transformation->copy(); 37 d_cnv( other.d_cnv ), 38 d_ts1( other.d_ts1 ), 39 d_transform( NULL ) 40 { 41 if ( other.d_transform ) 42 d_transform = other.d_transform->copy(); 122 43 } 123 44 … … 127 48 QwtScaleMap::~QwtScaleMap() 128 49 { 129 delete d_transform ation;50 delete d_transform; 130 51 } 131 52 … … 138 59 d_p2 = other.d_p2; 139 60 d_cnv = other.d_cnv; 140 141 delete d_transformation; 142 d_transformation = other.d_transformation->copy(); 61 d_ts1 = other.d_ts1; 62 63 delete d_transform; 64 d_transform = NULL; 65 66 if ( other.d_transform ) 67 d_transform = other.d_transform->copy(); 143 68 144 69 return *this; … … 148 73 Initialize the map with a transformation 149 74 */ 150 void QwtScaleMap::setTransformation( 151 QwtScaleTransformation *transformation ) 152 { 153 if ( transformation == NULL ) 154 return; 155 156 if ( transformation != d_transformation ) 75 void QwtScaleMap::setTransformation( QwtTransform *transform ) 76 { 77 if ( transform != d_transform ) 157 78 { 158 delete d_transform ation;159 d_transform ation = transformation;79 delete d_transform; 80 d_transform = transform; 160 81 } 161 82 … … 164 85 165 86 //! Get the transformation 166 const Qwt ScaleTransformation*QwtScaleMap::transformation() const167 { 168 return d_transform ation;87 const QwtTransform *QwtScaleMap::transformation() const 88 { 89 return d_transform; 169 90 } 170 91 … … 173 94 \param s1 first border 174 95 \param s2 second border 175 \warning logarithmic scales might be aligned to [LogMin, LogMax] 96 \warning scales might be aligned to 97 transformation depending boundaries 176 98 */ 177 99 void QwtScaleMap::setScaleInterval( double s1, double s2 ) 178 100 { 179 if ( d_transformation->type() == QwtScaleTransformation::Log10 )180 {181 if ( s1 < LogMin )182 s1 = LogMin;183 else if ( s1 > LogMax )184 s1 = LogMax;185 186 if ( s2 < LogMin )187 s2 = LogMin;188 else if ( s2 > LogMax )189 s2 = LogMax;190 }191 192 101 d_s1 = s1; 193 102 d_s2 = s2; 194 103 195 if ( d_transformation->type() != QwtScaleTransformation::Other ) 196 newFactor(); 104 if ( d_transform ) 105 { 106 d_s1 = d_transform->bounded( d_s1 ); 107 d_s2 = d_transform->bounded( d_s2 ); 108 } 109 110 updateFactor(); 197 111 } 198 112 … … 207 121 d_p2 = p2; 208 122 209 if ( d_transformation->type() != QwtScaleTransformation::Other ) 210 newFactor(); 211 } 212 213 /*! 214 \brief Re-calculate the conversion factor. 215 */ 216 void QwtScaleMap::newFactor() 217 { 218 d_cnv = 0.0; 219 220 switch ( d_transformation->type() ) 123 updateFactor(); 124 } 125 126 void QwtScaleMap::updateFactor() 127 { 128 d_ts1 = d_s1; 129 double ts2 = d_s2; 130 131 if ( d_transform ) 221 132 { 222 case QwtScaleTransformation::Linear: 223 { 224 if ( d_s2 != d_s1 ) 225 d_cnv = ( d_p2 - d_p1 ) / ( d_s2 - d_s1 ); 226 break; 227 } 228 case QwtScaleTransformation::Log10: 229 { 230 if ( d_s1 != 0 ) 231 d_cnv = ( d_p2 - d_p1 ) / log( d_s2 / d_s1 ); 232 break; 233 } 234 default:; 133 d_ts1 = d_transform->transform( d_ts1 ); 134 ts2 = d_transform->transform( ts2 ); 235 135 } 136 137 d_cnv = 1.0; 138 if ( d_ts1 != ts2 ) 139 d_cnv = ( d_p2 - d_p1 ) / ( ts2 - d_ts1 ); 236 140 } 237 141 … … 334 238 { 335 239 debug.nospace() << "QwtScaleMap(" 336 << static_cast<int>( map.transformation()->type())240 << map.transformation() 337 241 << ", s:" << map.s1() << "->" << map.s2() 338 242 << ", p:" << map.p1() << "->" << map.p2()
Note:
See TracChangeset
for help on using the changeset viewer.