diff --git a/app/PlotSubWindow.cpp b/app/PlotSubWindow.cpp index 35b019b..9605711 100644 --- a/app/PlotSubWindow.cpp +++ b/app/PlotSubWindow.cpp @@ -27,6 +27,15 @@ namespace plaYUVer { +Void PlotSubWindow::definePlotColors() +{ + m_arrayColorList.append( Qt::blue ); + m_arrayColorList.append( Qt::red ); + m_arrayColorList.append( Qt::green ); + m_arrayColorList.append( Qt::black ); + m_arrayColorList.append( Qt::cyan ); +} + PlotSubWindow::PlotSubWindow( QWidget * parent ) : SubWindowHandle( parent, SubWindowHandle::PLOT_SUBWINDOW ) { @@ -39,26 +48,6 @@ PlotSubWindow::PlotSubWindow( QWidget * parent ) : m_cPlotArea = new QCustomPlot( this ); setWidget( m_cPlotArea ); - Example(); - -} - -Void PlotSubWindow::Example() -{ - // add two new graphs and set their look: - m_cPlotArea->addGraph(); - m_cPlotArea->graph( 0 )->setPen( QPen( Qt::blue ) ); // line color blue for first graph - m_cPlotArea->graph( 0 )->setBrush( QBrush( QColor( 0, 0, 255, 20 ) ) ); // first graph will be filled with translucent blue - m_cPlotArea->addGraph(); - m_cPlotArea->graph( 1 )->setPen( QPen( Qt::red ) ); // line color red for second graph - // generate some points of data (y0 for first, y1 for second graph): - QVector x( 250 ), y0( 250 ), y1( 250 ); - for( int i = 0; i < 250; ++i ) - { - x[i] = i; - y0[i] = exp( -i / 150.0 ) * cos( i / 10.0 ); // exponentially decaying cosine - y1[i] = exp( -i / 150.0 ); // exponential envelope - } // configure right and top axis to show ticks but no labels: // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this) m_cPlotArea->xAxis2->setVisible( true ); @@ -68,19 +57,30 @@ Void PlotSubWindow::Example() // make left and bottom axes always transfer their ranges to right and top axes: connect( m_cPlotArea->xAxis, SIGNAL( rangeChanged(QCPRange) ), m_cPlotArea->xAxis2, SLOT( setRange(QCPRange) ) ); connect( m_cPlotArea->yAxis, SIGNAL( rangeChanged(QCPRange) ), m_cPlotArea->yAxis2, SLOT( setRange(QCPRange) ) ); - // pass data points to graphs: - m_cPlotArea->graph( 0 )->setData( x, y0 ); - m_cPlotArea->graph( 1 )->setData( x, y1 ); - // let the ranges scale themselves so graph 0 fits perfectly in the visible area: - m_cPlotArea->graph( 0 )->rescaleAxes(); - // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0): - m_cPlotArea->graph( 1 )->rescaleAxes( true ); - // Note: we could have also just called m_cPlotArea->rescaleAxes(); instead - // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking: + + definePlotColors(); + m_uiNumberPlots = 0; + m_cPlotArea->setInteractions( QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables ); } +Void PlotSubWindow::Example() +{ + // generate some points of data (y0 for first, y1 for second graph): + QVector x( 250 ), y0( 250 ), y1( 250 ); + for( int i = 0; i < 250; ++i ) + { + x[i] = i; + y0[i] = exp( -i / 150.0 ) * cos( i / 10.0 ); // exponentially decaying cosine + y1[i] = exp( -i / 150.0 ); // exponential envelope + } + + addPlot( x, y0 ); + addPlot( x, y1 ); + +} + PlotSubWindow::~PlotSubWindow() { delete m_cPlotArea; @@ -106,15 +106,37 @@ Void PlotSubWindow::scaleView( Double scale, QPoint center ) } -//QSize PlotSubWindow::sizeHint() const -//{ -// -//} -// -// -//QSize PlotSubWindow::sizeHint( const QSize & maxSize ) const -//{ -// -//} +QSize PlotSubWindow::sizeHint() const +{ + QSize maxSize; + QWidget *p = parentWidget(); + if( p ) + { + maxSize = p->size(); + } + else + { + maxSize = QApplication::desktop()->availableGeometry().size(); + } + return sizeHint( maxSize ); +} + +QSize PlotSubWindow::sizeHint( const QSize & maxSize ) const +{ + return maxSize; +} + +Void PlotSubWindow::addPlot( const QVector &key, const QVector &value ) +{ + QCPGraph *newPlot = m_cPlotArea->addGraph(); + newPlot->setPen( QPen( m_arrayColorList.at( m_uiNumberPlots ) ) ); // line color blue for first graph + newPlot->setBrush( QBrush( QColor( 0, 0, 255, 20 ) ) ); // first graph will be filled with translucent blue + // pass data points to graphs: + newPlot->setData( key, value ); + // let the ranges scale themselves so graph 0 fits perfectly in the visible area: + newPlot->rescaleAxes( m_uiNumberPlots > 1 ? true : false ); + + m_uiNumberPlots++; +} } // NAMESPACE diff --git a/app/PlotSubWindow.h b/app/PlotSubWindow.h index 9dfb063..c8da96c 100644 --- a/app/PlotSubWindow.h +++ b/app/PlotSubWindow.h @@ -44,6 +44,8 @@ Q_OBJECT private: QCustomPlot* m_cPlotArea; + QVector m_arrayColorList; + UInt m_uiNumberPlots; Void Example(); @@ -51,6 +53,8 @@ public: PlotSubWindow( QWidget * parent = 0 ); ~PlotSubWindow(); + Void definePlotColors(); + Void setTool( UInt uiTool ) { } @@ -71,8 +75,10 @@ public: /** * Size related functions */ -// QSize sizeHint() const; -// QSize sizeHint( const QSize & ) const; + QSize sizeHint() const; + QSize sizeHint( const QSize & ) const; + + Void addPlot(const QVector &key, const QVector &value); }; } // NAMESPACE diff --git a/app/QualityHandle.cpp b/app/QualityHandle.cpp index 0230970..646c80d 100644 --- a/app/QualityHandle.cpp +++ b/app/QualityHandle.cpp @@ -28,6 +28,7 @@ #include "VideoSubWindow.h" #include "PlotSubWindow.h" #include "DialogSubWindowSelector.h" +#include "lib/LibMemory.h" namespace plaYUVer { @@ -75,7 +76,7 @@ QMenu* QualityHandle::createMenu() m_pcSubMenuQualityMetrics->addActions( m_actionGroupQualityMetric->actions() ); m_pcMenuQuality->addAction( m_arrayActions[SELECT_REF_ACT] ); m_pcMenuQuality->addSeparator(); - //m_pcMenuQuality->addAction( m_arrayActions[PLOT_QUALITY] ); + m_pcMenuQuality->addAction( m_arrayActions[PLOT_QUALITY] ); return m_pcMenuQuality; } @@ -127,6 +128,62 @@ Void QualityHandle::update( VideoSubWindow* currSubWindow ) m_pcQualityHandleSideBar->updateCurrentWindow( currSubWindow ); } +QVector* QualityHandle::measureQuality( QVector apcWindowList ) +{ + QVector* padQualityValues; + UInt numberOfWindows = apcWindowList.size(); + UInt64 currFrames = 0; + UInt64 numberOfFrames = INT_MAX; + + QApplication::setOverrideCursor( Qt::WaitCursor ); + + //! Check reference window + for( UInt i = 0; i < numberOfWindows; i++ ) + { + if( !apcWindowList.at( i )->getRefSubWindow() ) + { + return NULL; + } + } + VideoSubWindow* pcReferenceWindow = apcWindowList.at( 0 )->getRefSubWindow(); + + for( UInt i = 0; i < numberOfWindows; i++ ) + { + currFrames = apcWindowList.at( i )->getInputStream()->getFrameNum(); + if( currFrames < numberOfFrames ) + numberOfFrames = currFrames; + apcWindowList.at( i )->stop(); + } + pcReferenceWindow->stop(); + + padQualityValues = new QVector [numberOfWindows + 1]; + + PlaYUVerFrame* pcReferenceFrame; + PlaYUVerFrame* pcCurrFrame; + for( UInt f = 1; f < numberOfFrames; f++ ) + { + padQualityValues[0].append( f ); + pcReferenceFrame = pcReferenceWindow->getCurrFrame(); + for( UInt i = 0; i < numberOfWindows; i++ ) + { + pcCurrFrame = apcWindowList.at( 0 )->getCurrFrame(); + padQualityValues[i + 1].append( pcCurrFrame->getQuality( 0, pcReferenceFrame, LUMA ) ); + apcWindowList.at( 0 )->play(); + apcWindowList.at( 0 )->playEvent(); + } + pcReferenceWindow->play(); + pcReferenceWindow->playEvent(); + } + for( UInt i = 0; i < numberOfWindows; i++ ) + { + apcWindowList.at( 0 )->stop(); + } + pcReferenceWindow->stop(); + QApplication::restoreOverrideCursor(); + + return padQualityValues; +} + Void QualityHandle::slotQualityMetricChanged( Int idx ) { m_actionGroupQualityMetric->actions().at( idx )->setChecked( true ); @@ -165,9 +222,24 @@ Void QualityHandle::slotSelectReference() Void QualityHandle::slotCreatePlot() { - PlotSubWindow* pcPlotWindow = new PlotSubWindow( m_pcParet ); - m_pcMainWindowManager->addSubWindow( pcPlotWindow ); - pcPlotWindow->show(); + VideoSubWindow* pcSubWindow = qobject_cast( m_pcMainWindowManager->activeSubWindow() ); + if( pcSubWindow ) + { + if( pcSubWindow->getRefSubWindow() ) + { + QVector apcWindowList; + apcWindowList.append( pcSubWindow ); + QVector* qualityVector = measureQuality( apcWindowList ); + + PlotSubWindow* pcPlotWindow = new PlotSubWindow( m_pcParet ); + + pcPlotWindow->addPlot( qualityVector[0], qualityVector[1] ); + + m_pcMainWindowManager->addSubWindow( pcPlotWindow ); + pcPlotWindow->show(); + + } + } } diff --git a/app/QualityHandle.h b/app/QualityHandle.h index faa42d5..29d683f 100644 --- a/app/QualityHandle.h +++ b/app/QualityHandle.h @@ -78,6 +78,8 @@ private: QDockWidget* m_pcQualityHandleDock; QualityMeasurementSidebar* m_pcQualityHandleSideBar; + QVector* measureQuality( QVector apcWindowList ); + Q_SIGNALS: void changed();