4242#include " utils.h"
4343#include < qwt_plot_shapeitem.h>
4444#include < QSettings>
45+ #include < qwt_picker_machine.h>
46+
47+
4548double zOffset = 0 ;
4649
4750class MyZoomer : public QwtPlotZoomer
4851{
4952public:
50- MyZoomer ( QWidget *canvas ):
51- QwtPlotZoomer ( canvas )
53+ ContourPlot* thePlot;
54+ MyZoomer ( QWidget *canvas ,ContourPlot* plot):
55+ QwtPlotZoomer ( canvas ), thePlot(plot)
5256 {
5357 setTrackerMode ( AlwaysOn );
5458 }
5559
5660 virtual QwtText trackerTextF ( const QPointF &pos ) const
5761 {
62+ if (thePlot->m_wf == 0 )
63+ return QwtText (" " );
5864 QColor bg ( Qt::white );
5965 bg.setAlpha ( 200 );
66+ int x = thePlot->invTransform (QwtPlot::xBottom, pos.x ());
67+ int y = thePlot->invTransform (QwtPlot::yLeft, pos.y ());
68+ double v = thePlot->d_spectrogram ->data ()->value (pos.x (),pos.y ());
6069
61- QwtText text = QwtPlotZoomer::trackerTextF ( pos );
70+ QwtText text (QString ().sprintf (" %lf" ,v));
71+ text.setFont (QFont (" Arial" ,12 ));
6272 text.setBackgroundBrush ( QBrush ( bg ) );
73+ thePlot->selected (pos);
6374 return text;
6475 }
6576signals:
@@ -69,14 +80,17 @@ class MyZoomer: public QwtPlotZoomer
6980
7081SpectrogramData::SpectrogramData (): m_wf(0 )
7182{
83+
7284}
7385
86+
7487void SpectrogramData::setSurface (wavefront *surface) {
7588 m_wf = surface;
7689 setInterval ( Qt::XAxis, QwtInterval (0 ,m_wf->workData .cols ));
7790 setInterval ( Qt::YAxis, QwtInterval (0 , m_wf->workData .rows ));
7891}
7992#include < qwt_round_scale_draw.h>
93+ extern double g_angle;
8094double SpectrogramData::value ( double x, double y ) const
8195{
8296
@@ -177,8 +191,8 @@ void ContourPlot::setZRange(){
177191
178192 }
179193 else if (m_zRangeMode == " Min/Max" ){
180- zmin = m_wf-> min ;
181- zmax = m_wf-> max ;
194+ zmin = m_min ;
195+ zmax = m_max ;
182196 }
183197 else if (m_zRangeMode == " Fractions of Wave" ){
184198 zmin = -m_waveRange/2 ;
@@ -195,6 +209,8 @@ void ContourPlot::setZRange(){
195209}
196210void ContourPlot::newDisplayErrorRange (double min,double max){
197211 QwtInterval zInt (min,max);
212+ m_min = min;
213+ m_max = max;
198214 SpectrogramData *data = (SpectrogramData*)d_spectrogram->data ();
199215 data->setInterval ( Qt::ZAxis, zInt);
200216 setColorMap (m_colorMapNdx);
@@ -277,6 +293,9 @@ void ContourPlot::ruler(){
277293
278294 item->attach ( this );
279295 }
296+
297+
298+
280299 QwtPlotMarker *yAxis = new QwtPlotMarker ();
281300 yAxis->setLineStyle (QwtPlotMarker::VLine);
282301 yAxis->setXValue (m_wf->data .cols /2 );
@@ -292,6 +311,52 @@ void ContourPlot::ruler(){
292311
293312 }
294313}
314+ void ContourPlot::moved (const QPointF pos){
315+
316+ }
317+
318+ void ContourPlot::selected (const QPointF& pos){
319+ if (m_wf==0 )
320+ return ;
321+
322+ int half = m_wf->data .rows /2 .;
323+ double delx = pos.x () - half;
324+ double dely = pos.y () - half;
325+ double angle = atan2 (dely,delx);
326+ if (angle != m_lastAngle){
327+ drawProfileLine (angle);
328+ emit sigPointSelected (pos);
329+ m_lastAngle = angle;
330+ }
331+ }
332+
333+ void ContourPlot::drawProfileLine (const double angle){
334+
335+ ruler ();
336+ double sina = sin (angle);
337+ double cosa = cos (angle);
338+ QPainterPath radials;
339+ int half = m_wf->data .rows /2 .;
340+ // move to start
341+ int startx = -half * cosa;
342+ int starty = -half * sina;
343+ radials.moveTo ( half + startx,half + starty);
344+ // line to end
345+ int endx = half - startx;
346+ int endy = half - starty;
347+ radials.lineTo (endx,endy);
348+ QwtPlotShapeItem *item = new QwtPlotShapeItem ( " " );
349+ item->setShape (radials);
350+ item->setPen (QColor (50 ,50 ,50 ,100 ),3 ,Qt::DashDotDotLine);
351+
352+ QwtPlotShapeItem *itemb = new QwtPlotShapeItem ( " " );
353+ itemb->setShape (radials);
354+ itemb->setPen (QColor (250 ,250 ,250 ,100 ),10 );
355+ itemb->attach (this );
356+ item->attach (this );
357+ replot ();
358+ }
359+
295360
296361void ContourPlot::setSurface (wavefront * wf) {
297362 m_wf = wf;
@@ -337,7 +402,7 @@ void ContourPlot::setSurface(wavefront * wf) {
337402
338403 plotLayout ()->setAlignCanvasToScales (true );
339404 showContoursChanged (contourRange);
340-
405+ tracker_-> setZoomBase ( true );
341406 replot ();
342407 // resize(QSize(width()-1,height()-1));
343408 // resize(QSize(width()+1,height()+1));
@@ -351,6 +416,15 @@ ContourPlot::ContourPlot( QWidget *parent, ContourTools *tools, bool minimal ):
351416 QwtPlot( parent ),m_wf(0 ),m_tools(tools), m_autoInterval(false ),m_minimal(minimal),m_contourPen(Qt::white)
352417{
353418 d_spectrogram = new QwtPlotSpectrogram ();
419+ picker_ = new QwtPlotPicker (this ->canvas ());
420+ picker_->setStateMachine (new QwtPickerClickPointMachine);
421+
422+ tracker_ = new MyZoomer (this ->canvas (), this );
423+
424+
425+ connect (picker_, SIGNAL (selected (const QPointF&)),
426+ SLOT (selected (const QPointF&)));
427+
354428 QSettings settings;
355429 m_colorMapNdx = settings.value (" colorMapType" ,0 ).toInt ();
356430 contourRange = settings.value (" contourRange" , .1 ).toDouble ();
@@ -457,6 +531,7 @@ void ContourPlot::setAlpha( int alpha )
457531 replot ();
458532}
459533
534+
460535#ifndef QT_NO_PRINTER
461536
462537void ContourPlot::printPlot ()
0 commit comments