Index: trunk/BNC/qwt/qwt_matrix_raster_data.cpp
===================================================================
--- trunk/BNC/qwt/qwt_matrix_raster_data.cpp	(revision 9383)
+++ trunk/BNC/qwt/qwt_matrix_raster_data.cpp	(revision 11158)
@@ -1,3 +1,3 @@
-/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
+/******************************************************************************
  * Qwt Widget Library
  * Copyright (C) 1997   Josef Wilgen
@@ -9,13 +9,45 @@
 
 #include "qwt_matrix_raster_data.h"
+#include "qwt_interval.h"
+
+#include <qvector.h>
 #include <qnumeric.h>
-#include <qmath.h>
+#include <qrect.h>
+
+static inline double qwtHermiteInterpolate(
+    double A, double B, double C, double D, double t )
+{
+    const double t2 = t * t;
+    const double t3 = t2 * t;
+
+    const double a = -A / 2.0 + ( 3.0 * B ) / 2.0 - ( 3.0 * C ) / 2.0 + D / 2.0;
+    const double b = A - ( 5.0 * B ) / 2.0 + 2.0 * C - D / 2.0;
+    const double c = -A / 2.0 + C / 2.0;
+    const double d = B;
+
+    return a * t3 + b * t2 + c * t + d;
+}
+
+static inline double qwtBicubicInterpolate(
+    double v00, double v10, double v20, double v30,
+    double v01, double v11, double v21, double v31,
+    double v02, double v12, double v22, double v32,
+    double v03, double v13, double v23, double v33,
+    double dx, double dy )
+{
+    const double v0 = qwtHermiteInterpolate( v00, v10, v20, v30, dx );
+    const double v1 = qwtHermiteInterpolate( v01, v11, v21, v31, dx );
+    const double v2 = qwtHermiteInterpolate( v02, v12, v22, v32, dx );
+    const double v3 = qwtHermiteInterpolate( v03, v13, v23, v33, dx );
+
+    return qwtHermiteInterpolate( v0, v1, v2, v3, dy );
+}
 
 class QwtMatrixRasterData::PrivateData
 {
-public:
-    PrivateData():
-        resampleMode(QwtMatrixRasterData::NearestNeighbour),
-        numColumns(0)
+  public:
+    PrivateData()
+        : resampleMode( QwtMatrixRasterData::NearestNeighbour )
+        , numColumns(0)
     {
     }
@@ -26,7 +58,8 @@
     }
 
+    QwtInterval intervals[3];
     QwtMatrixRasterData::ResampleMode resampleMode;
 
-    QVector<double> values;
+    QVector< double > values;
     int numColumns;
     int numRows;
@@ -39,5 +72,5 @@
 QwtMatrixRasterData::QwtMatrixRasterData()
 {
-    d_data = new PrivateData();
+    m_data = new PrivateData();
     update();
 }
@@ -46,5 +79,5 @@
 QwtMatrixRasterData::~QwtMatrixRasterData()
 {
-    delete d_data;
+    delete m_data;
 }
 
@@ -54,8 +87,8 @@
    \param mode Resampling mode
    \sa resampleMode(), value()
-*/
+ */
 void QwtMatrixRasterData::setResampleMode( ResampleMode mode )
 {
-    d_data->resampleMode = mode;
+    m_data->resampleMode = mode;
 }
 
@@ -63,8 +96,8 @@
    \return resampling algorithm
    \sa setResampleMode(), value()
-*/
+ */
 QwtMatrixRasterData::ResampleMode QwtMatrixRasterData::resampleMode() const
 {
-    return d_data->resampleMode;
+    return m_data->resampleMode;
 }
 
@@ -84,10 +117,25 @@
 
    \sa QwtRasterData::interval(), setValueMatrix()
-*/
+ */
 void QwtMatrixRasterData::setInterval(
-    Qt::Axis axis, const QwtInterval &interval )
-{
-    QwtRasterData::setInterval( axis, interval );
-    update();
+    Qt::Axis axis, const QwtInterval& interval )
+{
+    if ( axis >= 0 && axis <= 2 )
+    {
+        m_data->intervals[axis] = interval;
+        update();
+    }
+}
+
+/*!
+   \return Bounding interval for an axis
+   \sa setInterval
+ */
+QwtInterval QwtMatrixRasterData::interval( Qt::Axis axis ) const
+{
+    if ( axis >= 0 && axis <= 2 )
+        return m_data->intervals[ axis ];
+
+    return QwtInterval();
 }
 
@@ -104,10 +152,10 @@
 
    \sa valueMatrix(), numColumns(), numRows(), setInterval()()
-*/
+ */
 void QwtMatrixRasterData::setValueMatrix(
-    const QVector<double> &values, int numColumns )
-{
-    d_data->values = values;
-    d_data->numColumns = qMax( numColumns, 0 );
+    const QVector< double >& values, int numColumns )
+{
+    m_data->values = values;
+    m_data->numColumns = qMax( numColumns, 0 );
     update();
 }
@@ -116,26 +164,26 @@
    \return Value matrix
    \sa setValueMatrix(), numColumns(), numRows(), setInterval()
-*/
-const QVector<double> QwtMatrixRasterData::valueMatrix() const
-{
-    return d_data->values;
-}
-
-/*!
-  \brief Change a single value in the matrix
-
-  \param row Row index
-  \param col Column index
-  \param value New value
-
-  \sa value(), setValueMatrix()
-*/
+ */
+const QVector< double > QwtMatrixRasterData::valueMatrix() const
+{
+    return m_data->values;
+}
+
+/*!
+   \brief Change a single value in the matrix
+
+   \param row Row index
+   \param col Column index
+   \param value New value
+
+   \sa value(), setValueMatrix()
+ */
 void QwtMatrixRasterData::setValue( int row, int col, double value )
 {
-    if ( row >= 0 && row < d_data->numRows &&
-        col >= 0 && col < d_data->numColumns )
-    {
-        const int index = row * d_data->numColumns + col;
-        d_data->values.data()[ index ] = value;
+    if ( row >= 0 && row < m_data->numRows &&
+        col >= 0 && col < m_data->numColumns )
+    {
+        const int index = row * m_data->numColumns + col;
+        m_data->values.data()[ index ] = value;
     }
 }
@@ -144,8 +192,8 @@
    \return Number of columns of the value matrix
    \sa valueMatrix(), numRows(), setValueMatrix()
-*/
+ */
 int QwtMatrixRasterData::numColumns() const
 {
-    return d_data->numColumns;
+    return m_data->numColumns;
 }
 
@@ -153,8 +201,8 @@
    \return Number of rows of the value matrix
    \sa valueMatrix(), numColumns(), setValueMatrix()
-*/
+ */
 int QwtMatrixRasterData::numRows() const
 {
-    return d_data->numRows;
+    return m_data->numRows;
 }
 
@@ -178,11 +226,11 @@
 
    \sa ResampleMode, setMatrix(), setInterval()
-*/
-QRectF QwtMatrixRasterData::pixelHint( const QRectF &area ) const
+ */
+QRectF QwtMatrixRasterData::pixelHint( const QRectF& area ) const
 {
     Q_UNUSED( area )
 
     QRectF rect;
-    if ( d_data->resampleMode == NearestNeighbour )
+    if ( m_data->resampleMode == NearestNeighbour )
     {
         const QwtInterval intervalX = interval( Qt::XAxis );
@@ -191,5 +239,5 @@
         {
             rect = QRectF( intervalX.minValue(), intervalY.minValue(),
-                d_data->dx, d_data->dy );
+                m_data->dx, m_data->dy );
         }
     }
@@ -205,5 +253,5 @@
 
    \sa ResampleMode
-*/
+ */
 double QwtMatrixRasterData::value( double x, double y ) const
 {
@@ -216,10 +264,83 @@
     double value;
 
-    switch( d_data->resampleMode )
-    {
+    switch( m_data->resampleMode )
+    {
+        case BicubicInterpolation:
+        {
+            const double colF = ( x - xInterval.minValue() ) / m_data->dx;
+            const double rowF = ( y - yInterval.minValue() ) / m_data->dy;
+
+            const int col = qRound( colF );
+            const int row = qRound( rowF );
+
+            int col0 = col - 2;
+            int col1 = col - 1;
+            int col2 = col;
+            int col3 = col + 1;
+
+            if ( col1 < 0 )
+                col1 = col2;
+
+            if ( col0 < 0 )
+                col0 = col1;
+
+            if ( col2 >= m_data->numColumns )
+                col2 = col1;
+
+            if ( col3 >= m_data->numColumns )
+                col3 = col2;
+
+            int row0 = row - 2;
+            int row1 = row - 1;
+            int row2 = row;
+            int row3 = row + 1;
+
+            if ( row1 < 0 )
+                row1 = row2;
+
+            if ( row0 < 0 )
+                row0 = row1;
+
+            if ( row2 >= m_data->numRows )
+                row2 = row1;
+
+            if ( row3 >= m_data->numRows )
+                row3 = row2;
+
+            // First row
+            const double v00 = m_data->value( row0, col0 );
+            const double v10 = m_data->value( row0, col1 );
+            const double v20 = m_data->value( row0, col2 );
+            const double v30 = m_data->value( row0, col3 );
+
+            // Second row
+            const double v01 = m_data->value( row1, col0 );
+            const double v11 = m_data->value( row1, col1 );
+            const double v21 = m_data->value( row1, col2 );
+            const double v31 = m_data->value( row1, col3 );
+
+            // Third row
+            const double v02 = m_data->value( row2, col0 );
+            const double v12 = m_data->value( row2, col1 );
+            const double v22 = m_data->value( row2, col2 );
+            const double v32 = m_data->value( row2, col3 );
+
+            // Fourth row
+            const double v03 = m_data->value( row3, col0 );
+            const double v13 = m_data->value( row3, col1 );
+            const double v23 = m_data->value( row3, col2 );
+            const double v33 = m_data->value( row3, col3 );
+
+            value = qwtBicubicInterpolate(
+                v00, v10, v20, v30, v01, v11, v21, v31,
+                v02, v12, v22, v32, v03, v13, v23, v33,
+                colF - col + 0.5, rowF - row + 0.5 );
+
+            break;
+        }
         case BilinearInterpolation:
         {
-            int col1 = qRound( (x - xInterval.minValue() ) / d_data->dx ) - 1;
-            int row1 = qRound( (y - yInterval.minValue() ) / d_data->dy ) - 1;
+            int col1 = qRound( ( x - xInterval.minValue() ) / m_data->dx ) - 1;
+            int row1 = qRound( ( y - yInterval.minValue() ) / m_data->dy ) - 1;
             int col2 = col1 + 1;
             int row2 = row1 + 1;
@@ -227,24 +348,22 @@
             if ( col1 < 0 )
                 col1 = col2;
-            else if ( col2 >= static_cast<int>( d_data->numColumns ) )
+            else if ( col2 >= m_data->numColumns )
                 col2 = col1;
 
             if ( row1 < 0 )
                 row1 = row2;
-            else if ( row2 >= static_cast<int>( d_data->numRows ) )
+            else if ( row2 >= m_data->numRows )
                 row2 = row1;
 
-            const double v11 = d_data->value( row1, col1 );
-            const double v21 = d_data->value( row1, col2 );
-            const double v12 = d_data->value( row2, col1 );
-            const double v22 = d_data->value( row2, col2 );
-
-            const double x2 = xInterval.minValue() +
-                ( col2 + 0.5 ) * d_data->dx;
-            const double y2 = yInterval.minValue() +
-                ( row2 + 0.5 ) * d_data->dy;
-
-            const double rx = ( x2 - x ) / d_data->dx;
-            const double ry = ( y2 - y ) / d_data->dy;
+            const double v11 = m_data->value( row1, col1 );
+            const double v21 = m_data->value( row1, col2 );
+            const double v12 = m_data->value( row2, col1 );
+            const double v22 = m_data->value( row2, col2 );
+
+            const double x2 = xInterval.minValue() + ( col2 + 0.5 ) * m_data->dx;
+            const double y2 = yInterval.minValue() + ( row2 + 0.5 ) * m_data->dy;
+
+            const double rx = ( x2 - x ) / m_data->dx;
+            const double ry = ( y2 - y ) / m_data->dy;
 
             const double vr1 = rx * v11 + ( 1.0 - rx ) * v21;
@@ -258,6 +377,6 @@
         default:
         {
-            int row = int( (y - yInterval.minValue() ) / d_data->dy );
-            int col = int( (x - xInterval.minValue() ) / d_data->dx );
+            int row = int( ( y - yInterval.minValue() ) / m_data->dy );
+            int col = int( ( x - xInterval.minValue() ) / m_data->dx );
 
             // In case of intervals, where the maximum is included
@@ -266,11 +385,11 @@
             // from the last row/col
 
-            if ( row >= d_data->numRows )
-                row = d_data->numRows - 1;
-
-            if ( col >= d_data->numColumns )
-                col = d_data->numColumns - 1;
-
-            value = d_data->value( row, col );
+            if ( row >= m_data->numRows )
+                row = m_data->numRows - 1;
+
+            if ( col >= m_data->numColumns )
+                col = m_data->numColumns - 1;
+
+            value = m_data->value( row, col );
         }
     }
@@ -281,18 +400,18 @@
 void QwtMatrixRasterData::update()
 {
-    d_data->numRows = 0;
-    d_data->dx = 0.0;
-    d_data->dy = 0.0;
-
-    if ( d_data->numColumns > 0 )
-    {
-        d_data->numRows = d_data->values.size() / d_data->numColumns;
+    m_data->numRows = 0;
+    m_data->dx = 0.0;
+    m_data->dy = 0.0;
+
+    if ( m_data->numColumns > 0 )
+    {
+        m_data->numRows = m_data->values.size() / m_data->numColumns;
 
         const QwtInterval xInterval = interval( Qt::XAxis );
         const QwtInterval yInterval = interval( Qt::YAxis );
         if ( xInterval.isValid() )
-            d_data->dx = xInterval.width() / d_data->numColumns;
+            m_data->dx = xInterval.width() / m_data->numColumns;
         if ( yInterval.isValid() )
-            d_data->dy = yInterval.width() / d_data->numRows;
-    }
-}
+            m_data->dy = yInterval.width() / m_data->numRows;
+    }
+}
