Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_matrix_raster_data.cpp
- Timestamp:
- Nov 3, 2026, 10:53:35 AM (3 weeks ago)
- File:
-
- 1 edited
-
trunk/BNC/qwt/qwt_matrix_raster_data.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_matrix_raster_data.cpp
r9383 r11158 1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*-*****************************1 /****************************************************************************** 2 2 * Qwt Widget Library 3 3 * Copyright (C) 1997 Josef Wilgen … … 9 9 10 10 #include "qwt_matrix_raster_data.h" 11 #include "qwt_interval.h" 12 13 #include <qvector.h> 11 14 #include <qnumeric.h> 12 #include <qmath.h> 15 #include <qrect.h> 16 17 static inline double qwtHermiteInterpolate( 18 double A, double B, double C, double D, double t ) 19 { 20 const double t2 = t * t; 21 const double t3 = t2 * t; 22 23 const double a = -A / 2.0 + ( 3.0 * B ) / 2.0 - ( 3.0 * C ) / 2.0 + D / 2.0; 24 const double b = A - ( 5.0 * B ) / 2.0 + 2.0 * C - D / 2.0; 25 const double c = -A / 2.0 + C / 2.0; 26 const double d = B; 27 28 return a * t3 + b * t2 + c * t + d; 29 } 30 31 static inline double qwtBicubicInterpolate( 32 double v00, double v10, double v20, double v30, 33 double v01, double v11, double v21, double v31, 34 double v02, double v12, double v22, double v32, 35 double v03, double v13, double v23, double v33, 36 double dx, double dy ) 37 { 38 const double v0 = qwtHermiteInterpolate( v00, v10, v20, v30, dx ); 39 const double v1 = qwtHermiteInterpolate( v01, v11, v21, v31, dx ); 40 const double v2 = qwtHermiteInterpolate( v02, v12, v22, v32, dx ); 41 const double v3 = qwtHermiteInterpolate( v03, v13, v23, v33, dx ); 42 43 return qwtHermiteInterpolate( v0, v1, v2, v3, dy ); 44 } 13 45 14 46 class QwtMatrixRasterData::PrivateData 15 47 { 16 public: 17 PrivateData() :18 resampleMode(QwtMatrixRasterData::NearestNeighbour ),19 numColumns(0) 48 public: 49 PrivateData() 50 : resampleMode( QwtMatrixRasterData::NearestNeighbour ) 51 , numColumns(0) 20 52 { 21 53 } … … 26 58 } 27 59 60 QwtInterval intervals[3]; 28 61 QwtMatrixRasterData::ResampleMode resampleMode; 29 62 30 QVector< double> values;63 QVector< double > values; 31 64 int numColumns; 32 65 int numRows; … … 39 72 QwtMatrixRasterData::QwtMatrixRasterData() 40 73 { 41 d_data = new PrivateData();74 m_data = new PrivateData(); 42 75 update(); 43 76 } … … 46 79 QwtMatrixRasterData::~QwtMatrixRasterData() 47 80 { 48 delete d_data;81 delete m_data; 49 82 } 50 83 … … 54 87 \param mode Resampling mode 55 88 \sa resampleMode(), value() 56 */ 89 */ 57 90 void QwtMatrixRasterData::setResampleMode( ResampleMode mode ) 58 91 { 59 d_data->resampleMode = mode;92 m_data->resampleMode = mode; 60 93 } 61 94 … … 63 96 \return resampling algorithm 64 97 \sa setResampleMode(), value() 65 */ 98 */ 66 99 QwtMatrixRasterData::ResampleMode QwtMatrixRasterData::resampleMode() const 67 100 { 68 return d_data->resampleMode;101 return m_data->resampleMode; 69 102 } 70 103 … … 84 117 85 118 \sa QwtRasterData::interval(), setValueMatrix() 86 */ 119 */ 87 120 void QwtMatrixRasterData::setInterval( 88 Qt::Axis axis, const QwtInterval &interval ) 89 { 90 QwtRasterData::setInterval( axis, interval ); 91 update(); 121 Qt::Axis axis, const QwtInterval& interval ) 122 { 123 if ( axis >= 0 && axis <= 2 ) 124 { 125 m_data->intervals[axis] = interval; 126 update(); 127 } 128 } 129 130 /*! 131 \return Bounding interval for an axis 132 \sa setInterval 133 */ 134 QwtInterval QwtMatrixRasterData::interval( Qt::Axis axis ) const 135 { 136 if ( axis >= 0 && axis <= 2 ) 137 return m_data->intervals[ axis ]; 138 139 return QwtInterval(); 92 140 } 93 141 … … 104 152 105 153 \sa valueMatrix(), numColumns(), numRows(), setInterval()() 106 */ 154 */ 107 155 void QwtMatrixRasterData::setValueMatrix( 108 const QVector< double> &values, int numColumns )109 { 110 d_data->values = values;111 d_data->numColumns = qMax( numColumns, 0 );156 const QVector< double >& values, int numColumns ) 157 { 158 m_data->values = values; 159 m_data->numColumns = qMax( numColumns, 0 ); 112 160 update(); 113 161 } … … 116 164 \return Value matrix 117 165 \sa setValueMatrix(), numColumns(), numRows(), setInterval() 118 */ 119 const QVector< double> QwtMatrixRasterData::valueMatrix() const120 { 121 return d_data->values;122 } 123 124 /*! 125 \brief Change a single value in the matrix 126 127 \param row Row index 128 \param col Column index 129 \param value New value 130 131 \sa value(), setValueMatrix() 132 */ 166 */ 167 const QVector< double > QwtMatrixRasterData::valueMatrix() const 168 { 169 return m_data->values; 170 } 171 172 /*! 173 \brief Change a single value in the matrix 174 175 \param row Row index 176 \param col Column index 177 \param value New value 178 179 \sa value(), setValueMatrix() 180 */ 133 181 void QwtMatrixRasterData::setValue( int row, int col, double value ) 134 182 { 135 if ( row >= 0 && row < d_data->numRows &&136 col >= 0 && col < d_data->numColumns )137 { 138 const int index = row * d_data->numColumns + col;139 d_data->values.data()[ index ] = value;183 if ( row >= 0 && row < m_data->numRows && 184 col >= 0 && col < m_data->numColumns ) 185 { 186 const int index = row * m_data->numColumns + col; 187 m_data->values.data()[ index ] = value; 140 188 } 141 189 } … … 144 192 \return Number of columns of the value matrix 145 193 \sa valueMatrix(), numRows(), setValueMatrix() 146 */ 194 */ 147 195 int QwtMatrixRasterData::numColumns() const 148 196 { 149 return d_data->numColumns;197 return m_data->numColumns; 150 198 } 151 199 … … 153 201 \return Number of rows of the value matrix 154 202 \sa valueMatrix(), numColumns(), setValueMatrix() 155 */ 203 */ 156 204 int QwtMatrixRasterData::numRows() const 157 205 { 158 return d_data->numRows;206 return m_data->numRows; 159 207 } 160 208 … … 178 226 179 227 \sa ResampleMode, setMatrix(), setInterval() 180 */ 181 QRectF QwtMatrixRasterData::pixelHint( const QRectF &area ) const228 */ 229 QRectF QwtMatrixRasterData::pixelHint( const QRectF& area ) const 182 230 { 183 231 Q_UNUSED( area ) 184 232 185 233 QRectF rect; 186 if ( d_data->resampleMode == NearestNeighbour )234 if ( m_data->resampleMode == NearestNeighbour ) 187 235 { 188 236 const QwtInterval intervalX = interval( Qt::XAxis ); … … 191 239 { 192 240 rect = QRectF( intervalX.minValue(), intervalY.minValue(), 193 d_data->dx,d_data->dy );241 m_data->dx, m_data->dy ); 194 242 } 195 243 } … … 205 253 206 254 \sa ResampleMode 207 */ 255 */ 208 256 double QwtMatrixRasterData::value( double x, double y ) const 209 257 { … … 216 264 double value; 217 265 218 switch( d_data->resampleMode ) 219 { 266 switch( m_data->resampleMode ) 267 { 268 case BicubicInterpolation: 269 { 270 const double colF = ( x - xInterval.minValue() ) / m_data->dx; 271 const double rowF = ( y - yInterval.minValue() ) / m_data->dy; 272 273 const int col = qRound( colF ); 274 const int row = qRound( rowF ); 275 276 int col0 = col - 2; 277 int col1 = col - 1; 278 int col2 = col; 279 int col3 = col + 1; 280 281 if ( col1 < 0 ) 282 col1 = col2; 283 284 if ( col0 < 0 ) 285 col0 = col1; 286 287 if ( col2 >= m_data->numColumns ) 288 col2 = col1; 289 290 if ( col3 >= m_data->numColumns ) 291 col3 = col2; 292 293 int row0 = row - 2; 294 int row1 = row - 1; 295 int row2 = row; 296 int row3 = row + 1; 297 298 if ( row1 < 0 ) 299 row1 = row2; 300 301 if ( row0 < 0 ) 302 row0 = row1; 303 304 if ( row2 >= m_data->numRows ) 305 row2 = row1; 306 307 if ( row3 >= m_data->numRows ) 308 row3 = row2; 309 310 // First row 311 const double v00 = m_data->value( row0, col0 ); 312 const double v10 = m_data->value( row0, col1 ); 313 const double v20 = m_data->value( row0, col2 ); 314 const double v30 = m_data->value( row0, col3 ); 315 316 // Second row 317 const double v01 = m_data->value( row1, col0 ); 318 const double v11 = m_data->value( row1, col1 ); 319 const double v21 = m_data->value( row1, col2 ); 320 const double v31 = m_data->value( row1, col3 ); 321 322 // Third row 323 const double v02 = m_data->value( row2, col0 ); 324 const double v12 = m_data->value( row2, col1 ); 325 const double v22 = m_data->value( row2, col2 ); 326 const double v32 = m_data->value( row2, col3 ); 327 328 // Fourth row 329 const double v03 = m_data->value( row3, col0 ); 330 const double v13 = m_data->value( row3, col1 ); 331 const double v23 = m_data->value( row3, col2 ); 332 const double v33 = m_data->value( row3, col3 ); 333 334 value = qwtBicubicInterpolate( 335 v00, v10, v20, v30, v01, v11, v21, v31, 336 v02, v12, v22, v32, v03, v13, v23, v33, 337 colF - col + 0.5, rowF - row + 0.5 ); 338 339 break; 340 } 220 341 case BilinearInterpolation: 221 342 { 222 int col1 = qRound( (x - xInterval.minValue() ) / d_data->dx ) - 1;223 int row1 = qRound( (y - yInterval.minValue() ) / d_data->dy ) - 1;343 int col1 = qRound( ( x - xInterval.minValue() ) / m_data->dx ) - 1; 344 int row1 = qRound( ( y - yInterval.minValue() ) / m_data->dy ) - 1; 224 345 int col2 = col1 + 1; 225 346 int row2 = row1 + 1; … … 227 348 if ( col1 < 0 ) 228 349 col1 = col2; 229 else if ( col2 >= static_cast<int>( d_data->numColumns))350 else if ( col2 >= m_data->numColumns ) 230 351 col2 = col1; 231 352 232 353 if ( row1 < 0 ) 233 354 row1 = row2; 234 else if ( row2 >= static_cast<int>( d_data->numRows))355 else if ( row2 >= m_data->numRows ) 235 356 row2 = row1; 236 357 237 const double v11 = d_data->value( row1, col1 ); 238 const double v21 = d_data->value( row1, col2 ); 239 const double v12 = d_data->value( row2, col1 ); 240 const double v22 = d_data->value( row2, col2 ); 241 242 const double x2 = xInterval.minValue() + 243 ( col2 + 0.5 ) * d_data->dx; 244 const double y2 = yInterval.minValue() + 245 ( row2 + 0.5 ) * d_data->dy; 246 247 const double rx = ( x2 - x ) / d_data->dx; 248 const double ry = ( y2 - y ) / d_data->dy; 358 const double v11 = m_data->value( row1, col1 ); 359 const double v21 = m_data->value( row1, col2 ); 360 const double v12 = m_data->value( row2, col1 ); 361 const double v22 = m_data->value( row2, col2 ); 362 363 const double x2 = xInterval.minValue() + ( col2 + 0.5 ) * m_data->dx; 364 const double y2 = yInterval.minValue() + ( row2 + 0.5 ) * m_data->dy; 365 366 const double rx = ( x2 - x ) / m_data->dx; 367 const double ry = ( y2 - y ) / m_data->dy; 249 368 250 369 const double vr1 = rx * v11 + ( 1.0 - rx ) * v21; … … 258 377 default: 259 378 { 260 int row = int( (y - yInterval.minValue() ) / d_data->dy );261 int col = int( (x - xInterval.minValue() ) / d_data->dx );379 int row = int( ( y - yInterval.minValue() ) / m_data->dy ); 380 int col = int( ( x - xInterval.minValue() ) / m_data->dx ); 262 381 263 382 // In case of intervals, where the maximum is included … … 266 385 // from the last row/col 267 386 268 if ( row >= d_data->numRows )269 row = d_data->numRows - 1;270 271 if ( col >= d_data->numColumns )272 col = d_data->numColumns - 1;273 274 value = d_data->value( row, col );387 if ( row >= m_data->numRows ) 388 row = m_data->numRows - 1; 389 390 if ( col >= m_data->numColumns ) 391 col = m_data->numColumns - 1; 392 393 value = m_data->value( row, col ); 275 394 } 276 395 } … … 281 400 void QwtMatrixRasterData::update() 282 401 { 283 d_data->numRows = 0;284 d_data->dx = 0.0;285 d_data->dy = 0.0;286 287 if ( d_data->numColumns > 0 )288 { 289 d_data->numRows =d_data->values.size() /d_data->numColumns;402 m_data->numRows = 0; 403 m_data->dx = 0.0; 404 m_data->dy = 0.0; 405 406 if ( m_data->numColumns > 0 ) 407 { 408 m_data->numRows = m_data->values.size() / m_data->numColumns; 290 409 291 410 const QwtInterval xInterval = interval( Qt::XAxis ); 292 411 const QwtInterval yInterval = interval( Qt::YAxis ); 293 412 if ( xInterval.isValid() ) 294 d_data->dx = xInterval.width() /d_data->numColumns;413 m_data->dx = xInterval.width() / m_data->numColumns; 295 414 if ( yInterval.isValid() ) 296 d_data->dy = yInterval.width() /d_data->numRows;297 } 298 } 415 m_data->dy = yInterval.width() / m_data->numRows; 416 } 417 }
Note:
See TracChangeset
for help on using the changeset viewer.
