Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (3 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_matrix_raster_data.cpp

    r9383 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    99
    1010#include "qwt_matrix_raster_data.h"
     11#include "qwt_interval.h"
     12
     13#include <qvector.h>
    1114#include <qnumeric.h>
    12 #include <qmath.h>
     15#include <qrect.h>
     16
     17static 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
     31static 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}
    1345
    1446class QwtMatrixRasterData::PrivateData
    1547{
    16 public:
    17     PrivateData():
    18         resampleMode(QwtMatrixRasterData::NearestNeighbour),
    19         numColumns(0)
     48  public:
     49    PrivateData()
     50        : resampleMode( QwtMatrixRasterData::NearestNeighbour )
     51        , numColumns(0)
    2052    {
    2153    }
    … …  
    2658    }
    2759
     60    QwtInterval intervals[3];
    2861    QwtMatrixRasterData::ResampleMode resampleMode;
    2962
    30     QVector<double> values;
     63    QVector< double > values;
    3164    int numColumns;
    3265    int numRows;
    … …  
    3972QwtMatrixRasterData::QwtMatrixRasterData()
    4073{
    41     d_data = new PrivateData();
     74    m_data = new PrivateData();
    4275    update();
    4376}
    … …  
    4679QwtMatrixRasterData::~QwtMatrixRasterData()
    4780{
    48     delete d_data;
     81    delete m_data;
    4982}
    5083
    … …  
    5487   \param mode Resampling mode
    5588   \sa resampleMode(), value()
    56 */
     89 */
    5790void QwtMatrixRasterData::setResampleMode( ResampleMode mode )
    5891{
    59     d_data->resampleMode = mode;
     92    m_data->resampleMode = mode;
    6093}
    6194
    … …  
    6396   \return resampling algorithm
    6497   \sa setResampleMode(), value()
    65 */
     98 */
    6699QwtMatrixRasterData::ResampleMode QwtMatrixRasterData::resampleMode() const
    67100{
    68     return d_data->resampleMode;
     101    return m_data->resampleMode;
    69102}
    70103
    … …  
    84117
    85118   \sa QwtRasterData::interval(), setValueMatrix()
    86 */
     119 */
    87120void 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 */
     134QwtInterval QwtMatrixRasterData::interval( Qt::Axis axis ) const
     135{
     136    if ( axis >= 0 && axis <= 2 )
     137        return m_data->intervals[ axis ];
     138
     139    return QwtInterval();
    92140}
    93141
    … …  
    104152
    105153   \sa valueMatrix(), numColumns(), numRows(), setInterval()()
    106 */
     154 */
    107155void 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 );
    112160    update();
    113161}
    … …  
    116164   \return Value matrix
    117165   \sa setValueMatrix(), numColumns(), numRows(), setInterval()
    118 */
    119 const QVector<double> QwtMatrixRasterData::valueMatrix() const
    120 {
    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 */
     167const 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 */
    133181void QwtMatrixRasterData::setValue( int row, int col, double value )
    134182{
    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;
    140188    }
    141189}
    … …  
    144192   \return Number of columns of the value matrix
    145193   \sa valueMatrix(), numRows(), setValueMatrix()
    146 */
     194 */
    147195int QwtMatrixRasterData::numColumns() const
    148196{
    149     return d_data->numColumns;
     197    return m_data->numColumns;
    150198}
    151199
    … …  
    153201   \return Number of rows of the value matrix
    154202   \sa valueMatrix(), numColumns(), setValueMatrix()
    155 */
     203 */
    156204int QwtMatrixRasterData::numRows() const
    157205{
    158     return d_data->numRows;
     206    return m_data->numRows;
    159207}
    160208
    … …  
    178226
    179227   \sa ResampleMode, setMatrix(), setInterval()
    180 */
    181 QRectF QwtMatrixRasterData::pixelHint( const QRectF &area ) const
     228 */
     229QRectF QwtMatrixRasterData::pixelHint( const QRectF& area ) const
    182230{
    183231    Q_UNUSED( area )
    184232
    185233    QRectF rect;
    186     if ( d_data->resampleMode == NearestNeighbour )
     234    if ( m_data->resampleMode == NearestNeighbour )
    187235    {
    188236        const QwtInterval intervalX = interval( Qt::XAxis );
    … …  
    191239        {
    192240            rect = QRectF( intervalX.minValue(), intervalY.minValue(),
    193                 d_data->dx, d_data->dy );
     241                m_data->dx, m_data->dy );
    194242        }
    195243    }
    … …  
    205253
    206254   \sa ResampleMode
    207 */
     255 */
    208256double QwtMatrixRasterData::value( double x, double y ) const
    209257{
    … …  
    216264    double value;
    217265
    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        }
    220341        case BilinearInterpolation:
    221342        {
    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;
    224345            int col2 = col1 + 1;
    225346            int row2 = row1 + 1;
    … …  
    227348            if ( col1 < 0 )
    228349                col1 = col2;
    229             else if ( col2 >= static_cast<int>( d_data->numColumns ) )
     350            else if ( col2 >= m_data->numColumns )
    230351                col2 = col1;
    231352
    232353            if ( row1 < 0 )
    233354                row1 = row2;
    234             else if ( row2 >= static_cast<int>( d_data->numRows ) )
     355            else if ( row2 >= m_data->numRows )
    235356                row2 = row1;
    236357
    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;
    249368
    250369            const double vr1 = rx * v11 + ( 1.0 - rx ) * v21;
    … …  
    258377        default:
    259378        {
    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 );
    262381
    263382            // In case of intervals, where the maximum is included
    … …  
    266385            // from the last row/col
    267386
    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 );
    275394        }
    276395    }
    … …  
    281400void QwtMatrixRasterData::update()
    282401{
    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;
    290409
    291410        const QwtInterval xInterval = interval( Qt::XAxis );
    292411        const QwtInterval yInterval = interval( Qt::YAxis );
    293412        if ( xInterval.isValid() )
    294             d_data->dx = xInterval.width() / d_data->numColumns;
     413            m_data->dx = xInterval.width() / m_data->numColumns;
    295414        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.