Add files from zip
This commit is contained in:
209
examples/polarspectrogram/Plot.cpp
Normal file
209
examples/polarspectrogram/Plot.cpp
Normal file
@@ -0,0 +1,209 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Plot.h"
|
||||
|
||||
#include <QwtRasterData>
|
||||
#include <QwtPolarPanner>
|
||||
#include <QwtPolarMagnifier>
|
||||
#include <QwtPolarGrid>
|
||||
#include <QwtPolarSpectrogram>
|
||||
#include <QwtPolarRenderer>
|
||||
#include <QwtPolarPicker>
|
||||
#include <QwtPickerMachine>
|
||||
#include <QwtScaleDiv>
|
||||
#include <QwtRoundScaleDraw>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QPen>
|
||||
#include <QLocale>
|
||||
|
||||
namespace
|
||||
{
|
||||
class Picker : public QwtPolarPicker
|
||||
{
|
||||
public:
|
||||
Picker( QwtPolarCanvas* canvas )
|
||||
: QwtPolarPicker( canvas )
|
||||
{
|
||||
setStateMachine( new QwtPickerDragPointMachine() );
|
||||
setRubberBand( QwtPicker::NoRubberBand );
|
||||
setTrackerMode( ActiveOnly );
|
||||
}
|
||||
|
||||
virtual QwtText trackerTextPolar( const QwtPointPolar& pos ) const QWT_OVERRIDE
|
||||
{
|
||||
QColor bg( Qt::white );
|
||||
bg.setAlpha( 200 );
|
||||
|
||||
QwtText text = QwtPolarPicker::trackerTextPolar( pos );
|
||||
text.setBackgroundBrush( QBrush( bg ) );
|
||||
return text;
|
||||
}
|
||||
};
|
||||
|
||||
// Pointless synthetic data, showing something nice
|
||||
|
||||
class SpectrogramData : public QwtRasterData
|
||||
{
|
||||
public:
|
||||
SpectrogramData()
|
||||
{
|
||||
m_interval[Qt::ZAxis].setInterval( 0.0, 10.0 );
|
||||
}
|
||||
|
||||
virtual double value( double azimuth, double radius ) const QWT_OVERRIDE
|
||||
{
|
||||
const double c = 0.842;
|
||||
const double x = radius / 10.0 * 3.0 - 1.5;
|
||||
const double y = azimuth / ( 2 * M_PI ) * 3.0 - 1.5;
|
||||
|
||||
const double v1 = qwtSqr( x ) + ( y - c ) * ( y + c );
|
||||
const double v2 = 2 * x * ( y + c );
|
||||
|
||||
const double v = 1.0 / ( qwtSqr( v1 ) + qwtSqr( v2 ) );
|
||||
return v;
|
||||
}
|
||||
|
||||
virtual QwtInterval interval( Qt::Axis axis ) const QWT_OVERRIDE
|
||||
{
|
||||
return m_interval[ axis ];
|
||||
}
|
||||
|
||||
private:
|
||||
QwtInterval m_interval[3];
|
||||
};
|
||||
|
||||
class AzimuthScaleDraw : public QwtRoundScaleDraw
|
||||
{
|
||||
public:
|
||||
virtual QwtText label( double value ) const QWT_OVERRIDE
|
||||
{
|
||||
if ( qFuzzyCompare( fmod( value, 2 * M_PI ), 0.0 ) )
|
||||
{
|
||||
return QString( "0" );
|
||||
}
|
||||
|
||||
if ( qFuzzyCompare( fmod( value, M_PI_4 ), 0.0 ) )
|
||||
{
|
||||
QString text;
|
||||
if ( !qFuzzyCompare( value, M_PI ) )
|
||||
{
|
||||
text += QLocale().toString( value / M_PI );
|
||||
text += " ";
|
||||
}
|
||||
text += "<FONT face=Symbol size=4>p</FONT>";
|
||||
return text;
|
||||
}
|
||||
|
||||
return QwtRoundScaleDraw::label( value );
|
||||
}
|
||||
};
|
||||
|
||||
class Grid : public QwtPolarGrid
|
||||
{
|
||||
public:
|
||||
Grid()
|
||||
{
|
||||
setPen( QPen( Qt::white ) );
|
||||
|
||||
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
|
||||
{
|
||||
showGrid( scaleId );
|
||||
showMinorGrid( scaleId );
|
||||
|
||||
QPen minorPen( Qt::gray );
|
||||
setMinorGridPen( scaleId, minorPen );
|
||||
}
|
||||
|
||||
setAxisPen( QwtPolar::AxisAzimuth, QPen( Qt::black ) );
|
||||
setAzimuthScaleDraw( new AzimuthScaleDraw() );
|
||||
showAxis( QwtPolar::AxisAzimuth, true );
|
||||
showAxis( QwtPolar::AxisLeft, false );
|
||||
showAxis( QwtPolar::AxisRight, true );
|
||||
showAxis( QwtPolar::AxisTop, false );
|
||||
showAxis( QwtPolar::AxisBottom, false );
|
||||
showGrid( QwtPolar::Azimuth, true );
|
||||
showGrid( QwtPolar::Radius, true );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Plot::Plot( QWidget* parent )
|
||||
: QwtPolarPlot( parent )
|
||||
{
|
||||
setAutoReplot( false );
|
||||
setPlotBackground( Qt::darkBlue );
|
||||
|
||||
// scales
|
||||
setScale( QwtPolar::Azimuth, 0.0, 2 * M_PI, M_PI_4 );
|
||||
setScaleMaxMinor( QwtPolar::Azimuth, 2 );
|
||||
|
||||
setScale( QwtPolar::Radius, 0.0, 10.0 );
|
||||
setScaleMaxMinor( QwtPolar::Radius, 2 );
|
||||
|
||||
// grids
|
||||
m_grid = new Grid();
|
||||
m_grid->attach( this );
|
||||
|
||||
// spectrogram
|
||||
|
||||
m_spectrogram = new QwtPolarSpectrogram();
|
||||
m_spectrogram->setPaintAttribute(
|
||||
QwtPolarSpectrogram::ApproximatedAtan, true );
|
||||
m_spectrogram->setRenderThreadCount( 0 ); // use multi threading
|
||||
m_spectrogram->setData( new SpectrogramData() );
|
||||
m_spectrogram->attach( this );
|
||||
|
||||
m_spectrogram->setZ( 1.0 );
|
||||
m_grid->setZ( 2.0 );
|
||||
|
||||
Picker* picker = new Picker( canvas() );
|
||||
picker->setMousePattern( QwtEventPattern::MouseSelect1, Qt::RightButton );
|
||||
|
||||
QwtPolarMagnifier* magnifier = new QwtPolarMagnifier( canvas() );
|
||||
magnifier->setMouseButton( Qt::RightButton, Qt::ShiftModifier );
|
||||
|
||||
new QwtPolarPanner( canvas() );
|
||||
}
|
||||
|
||||
QwtPolarSpectrogram* Plot::spectrogram()
|
||||
{
|
||||
return m_spectrogram;
|
||||
}
|
||||
|
||||
void Plot::rotate()
|
||||
{
|
||||
const double interval = 15.0; // degrees
|
||||
|
||||
double origin = azimuthOrigin() / M_PI * 180.0;
|
||||
origin = qRound( origin / interval ) * interval + interval;
|
||||
|
||||
setAzimuthOrigin( origin / 180.0 * M_PI );
|
||||
replot();
|
||||
}
|
||||
|
||||
void Plot::mirror()
|
||||
{
|
||||
const double a1 = scaleDiv( QwtPolar::Azimuth )->upperBound();
|
||||
const double a2 = scaleDiv( QwtPolar::Azimuth )->lowerBound();
|
||||
|
||||
setScale( QwtPolar::Azimuth, a1, a2, qAbs( a2 - a1 ) / 8.0 );
|
||||
replot();
|
||||
}
|
||||
|
||||
void Plot::exportDocument()
|
||||
{
|
||||
QwtPolarRenderer renderer;
|
||||
renderer.exportTo( this, "spectrogram.pdf", QSizeF( 200, 200 ), 300 );
|
||||
}
|
||||
|
||||
void Plot::showGrid( bool on )
|
||||
{
|
||||
m_grid->setVisible( on );
|
||||
replot();
|
||||
}
|
||||
|
||||
#include "moc_Plot.cpp"
|
||||
30
examples/polarspectrogram/Plot.h
Normal file
30
examples/polarspectrogram/Plot.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QwtPolarPlot>
|
||||
|
||||
class QwtPolarGrid;
|
||||
class QwtPolarSpectrogram;
|
||||
|
||||
class Plot : public QwtPolarPlot
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Plot( QWidget* = NULL );
|
||||
QwtPolarSpectrogram* spectrogram();
|
||||
|
||||
public Q_SLOTS:
|
||||
void exportDocument();
|
||||
void showGrid( bool );
|
||||
void rotate();
|
||||
void mirror();
|
||||
|
||||
private:
|
||||
QwtPolarGrid* m_grid;
|
||||
QwtPolarSpectrogram* m_spectrogram;
|
||||
};
|
||||
70
examples/polarspectrogram/PlotWindow.cpp
Normal file
70
examples/polarspectrogram/PlotWindow.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "Plot.h"
|
||||
#include "PlotWindow.h"
|
||||
|
||||
#include <QwtScaleEngine>
|
||||
#include <QwtRasterData>
|
||||
#include <QwtPolarSpectrogram>
|
||||
#include <QwtScaleWidget>
|
||||
#include <QwtColorMap>
|
||||
|
||||
#include <QLayout>
|
||||
|
||||
namespace
|
||||
{
|
||||
class ColorMap : public QwtLinearColorMap
|
||||
{
|
||||
public:
|
||||
ColorMap()
|
||||
: QwtLinearColorMap( Qt::darkBlue, Qt::yellow )
|
||||
{
|
||||
#if 1
|
||||
addColorStop( 0.00, Qt::black );
|
||||
addColorStop( 0.05, Qt::darkRed );
|
||||
#else
|
||||
addColorStop( 0.05, Qt::blue );
|
||||
#endif
|
||||
addColorStop( 0.3, Qt::cyan );
|
||||
addColorStop( 0.6, Qt::green );
|
||||
addColorStop( 0.98, Qt::red );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
PlotWindow::PlotWindow( QWidget* parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
m_plot = new Plot();
|
||||
|
||||
m_colorScale = new QwtScaleWidget();
|
||||
m_colorScale->setAlignment( QwtScaleDraw::RightScale );
|
||||
m_colorScale->setColorBarEnabled( true );
|
||||
|
||||
QwtText title( "Intensity" );
|
||||
QFont font = m_colorScale->font();
|
||||
font.setBold( true );
|
||||
title.setFont( font );
|
||||
m_colorScale->setTitle( title );
|
||||
|
||||
const QwtInterval interval =
|
||||
m_plot->spectrogram()->data()->interval( Qt::ZAxis );
|
||||
|
||||
m_colorScale->setColorMap( interval, new ColorMap() );
|
||||
m_plot->spectrogram()->setColorMap( new ColorMap() );
|
||||
|
||||
QwtLinearScaleEngine scaleEngine;
|
||||
m_colorScale->setScaleDiv(
|
||||
scaleEngine.divideScale( interval.minValue(), interval.maxValue(), 8, 5 ) );
|
||||
|
||||
int startDist, endDist;
|
||||
m_colorScale->getBorderDistHint( startDist, endDist );
|
||||
m_colorScale->setBorderDist( startDist, endDist );
|
||||
|
||||
QHBoxLayout* layout = new QHBoxLayout( this );
|
||||
layout->addWidget( m_plot, 10 );
|
||||
layout->addWidget( m_colorScale, 10 );
|
||||
}
|
||||
23
examples/polarspectrogram/PlotWindow.h
Normal file
23
examples/polarspectrogram/PlotWindow.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class Plot;
|
||||
class QwtScaleWidget;
|
||||
|
||||
class PlotWindow : public QWidget
|
||||
{
|
||||
public:
|
||||
PlotWindow( QWidget* = NULL );
|
||||
|
||||
Plot* plot() { return m_plot; }
|
||||
|
||||
private:
|
||||
Plot* m_plot;
|
||||
QwtScaleWidget* m_colorScale;
|
||||
};
|
||||
74
examples/polarspectrogram/main.cpp
Normal file
74
examples/polarspectrogram/main.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*****************************************************************************
|
||||
* Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
* This file may be used under the terms of the 3-clause BSD License
|
||||
*****************************************************************************/
|
||||
|
||||
#include "PlotWindow.h"
|
||||
#include "Plot.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
|
||||
namespace
|
||||
{
|
||||
class ToolButton : public QToolButton
|
||||
{
|
||||
public:
|
||||
ToolButton( const QString& text, QWidget* parent = NULL )
|
||||
: QToolButton( parent )
|
||||
{
|
||||
setText( text );
|
||||
setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
|
||||
};
|
||||
};
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
public:
|
||||
MainWindow( QWidget* = NULL );
|
||||
};
|
||||
}
|
||||
|
||||
MainWindow::MainWindow( QWidget* parent )
|
||||
: QMainWindow( parent )
|
||||
{
|
||||
PlotWindow* plotWindow = new PlotWindow();
|
||||
setCentralWidget( plotWindow );
|
||||
|
||||
ToolButton* btnGrid = new ToolButton( "Grid" );
|
||||
btnGrid->setCheckable( true );
|
||||
btnGrid->setChecked( true );
|
||||
|
||||
ToolButton* btnExport = new ToolButton( "Export" );
|
||||
ToolButton* btnRotate = new ToolButton( "Rotate" );
|
||||
ToolButton* btnMirror = new ToolButton( "Mirror" );
|
||||
|
||||
QToolBar* toolBar = new QToolBar();
|
||||
|
||||
toolBar->addWidget( btnExport );
|
||||
toolBar->addWidget( btnGrid );
|
||||
toolBar->addWidget( btnRotate );
|
||||
toolBar->addWidget( btnMirror );
|
||||
|
||||
addToolBar( toolBar );
|
||||
|
||||
Plot* plot = plotWindow->plot();
|
||||
|
||||
connect( btnExport, SIGNAL(clicked()), plot, SLOT(exportDocument()) );
|
||||
connect( btnGrid, SIGNAL(toggled(bool)), plot, SLOT(showGrid(bool)) );
|
||||
connect( btnRotate, SIGNAL(clicked()), plot, SLOT(rotate()) );
|
||||
connect( btnMirror, SIGNAL(clicked()), plot, SLOT(mirror()) );
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
|
||||
MainWindow window;
|
||||
window.resize( 700, 600 );
|
||||
window.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
17
examples/polarspectrogram/polarspectrogram.pro
Normal file
17
examples/polarspectrogram/polarspectrogram.pro
Normal file
@@ -0,0 +1,17 @@
|
||||
######################################################################
|
||||
# Qwt Polar Examples - Copyright (C) 2008 Uwe Rathmann
|
||||
# This file may be used under the terms of the 3-clause BSD License
|
||||
######################################################################
|
||||
|
||||
include( $${PWD}/../examples.pri )
|
||||
|
||||
TARGET = polarspectrogram
|
||||
|
||||
HEADERS = \
|
||||
Plot.h \
|
||||
PlotWindow.h
|
||||
|
||||
SOURCES = \
|
||||
Plot.cpp \
|
||||
PlotWindow.cpp \
|
||||
main.cpp
|
||||
Reference in New Issue
Block a user