Results 1 to 11 of 11

Thread: Random markers from nowhere.

  1. #1
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Random markers from nowhere.

    Hey.

    I've a plot with a curve and a bunch of markers on it.
    When zooming in sometimes I get some random markers apearing.
    ufos.jpg

    Points with text are added by me, all other points appear from somewhere.

    I have no idea why it's happening. Maybe I'm missing some zoomer setting?

    Anyway, I've created simple example app to demonstrate the issue:
    Qt Code:
    1. //mainwindow.h
    2. #ifndef MAINWINDOW_H
    3. #define MAINWINDOW_H
    4.  
    5. #include <QtGui/QMainWindow>
    6.  
    7. class QwtPlot;
    8.  
    9. class MainWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MainWindow(QWidget *parent = 0);
    15. ~MainWindow();
    16.  
    17. private:
    18. void addCurve( void );
    19. void addMarkers( void );
    20.  
    21. QwtPlot* plot;
    22. QwtPlotZoomer* zoomer;
    23.  
    24. QVector<double> x;
    25. QVector<double> y;
    26. };
    27.  
    28. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. // mainwindow.cpp
    2. #include "mainwindow.h"
    3.  
    4. #include <qwt_plot.h>
    5. #include <qwt_plot_curve.h>
    6. #include <qwt_plot_marker.h>
    7. #include <qwt_symbol.h>
    8. #include <qwt_plot_zoomer.h>
    9.  
    10. MainWindow::MainWindow(QWidget *parent)
    11. : QMainWindow(parent)
    12. {
    13. this->plot = new QwtPlot(this);
    14. this->zoomer = new QwtPlotZoomer(this->plot->canvas());
    15.  
    16. this->addCurve();
    17. this->addMarkers();
    18.  
    19. this->zoomer->setZoomBase();;
    20. this->setCentralWidget(this->plot);
    21. }
    22.  
    23. MainWindow::~MainWindow()
    24. {
    25.  
    26. }
    27.  
    28. void MainWindow::addCurve( void )
    29. {
    30. int count = 20000;
    31.  
    32. for(int i = 0; i < count; ++i)
    33. {
    34. this->x.append(i);
    35. this->y.append(i);
    36. }
    37.  
    38. QwtPlotCurve* curve = new QwtPlotCurve();
    39. curve->setRawData(this->x.constBegin(), this->y.constBegin(), this->x.size());
    40. curve->attach(this->plot);
    41. }
    42.  
    43. void MainWindow::addMarkers( void )
    44. {
    45. int count = 5000;
    46. int step = this->x.size()/count;
    47.  
    48. for(int i = 0; i < count; ++i)
    49. {
    50. int x = i*step;
    51. int y = this->y[x];
    52.  
    53. m->setSymbol(QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::red), QPen(Qt::red), QSize(5,5)));
    54. m->setValue(x, y);
    55. m->setLabel(QString("%1x%2").arg(x).arg(y));
    56.  
    57. m->attach(this->plot);
    58. }
    59. }
    To copy to clipboard, switch view to plain text mode 

    Any suggestions how to get rid of that UFOs are welcome.

    PS: I'm running w7 64 bit with qt 4.6.3 and qwt 5.2.0.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    Ah, I forgot to add that it doesn't happen every time you zoom in.
    The more markers and/or deeper you zoom the more likely it will happen but sometimes you have to try several times to see it.

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    I've just tested 6.0.1 - the same issue

    Any idea how to solve it?

  4. #4
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Random markers from nowhere.

    Did you also look at the Y scale? It shows negative values which is rather surprising when zooming into a trace consisting of positive values only.
    I've tried to reproduce the behavior in my environment (linux 64 Bit + qwt 5.1.1), but had no luck.

    With my application I ran into a similar behavior with deep zooming some time ago. Here the reason was an integer overflow in my overwrite of the plot curve class (overwriting the drawLines() method).

  5. The following user says thank you to ars for this useful post:

    Spitfire (3rd November 2011)

  6. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Question Re: Random markers from nowhere.

    Thank for the answer!

    The nevagive Y value is there because the curve on the image goes from +300 to -300.
    The example provided doesn't have negative values and the same happens.

    I will try it on linux later today just to make sure.
    Sometimes you have to zoom in (deep) several times to see the extra markers.
    I can get them almost every time, and the more complex curve is the easier to reproduce it.

    At the beggining I also though that I've messed something up but it happens with clean project so that's not it.

    I hope that the issue can be resolved as it's a show stopper in the project I work on now ;/


    Added after 1 29 minutes:


    I've checked linux build and it seems fine.

    I've also checked Qt 4.7.4 on windows and issue is still there.

    I've updated the example so now you don't have to look for places where it occurs, just click buttons on the top and plot will zoom to where I've found alien markers to be.
    Note: every marker without text is something that should not be there.

    Qt Code:
    1. //mainwindow.h
    2. #ifndef MAINWINDOW_H
    3. #define MAINWINDOW_H
    4.  
    5. #include <QtGui/QMainWindow>
    6.  
    7. class QwtPlot;
    8.  
    9. class MainWindow : public QMainWindow
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. MainWindow(QWidget *parent = 0);
    15. ~MainWindow();
    16.  
    17. private slots:
    18. void zoom1( void );
    19. void zoom2( void );
    20. void zoom3( void );
    21. void zoom4( void );
    22. void zoom5( void );
    23. void zoom6( void );
    24.  
    25. private:
    26. void addCurve( void );
    27. void addMarkers( void );
    28.  
    29. QwtPlot* plot;
    30. QwtPlotZoomer* zoomer;
    31.  
    32. QVector<double> x;
    33. QVector<double> y;
    34. };
    35.  
    36. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //mainwindow.cpp
    2. #include "mainwindow.h"
    3.  
    4. #include <QToolBar>
    5.  
    6. #include <qwt_plot.h>
    7. #include <qwt_plot_curve.h>
    8. #include <qwt_plot_marker.h>
    9. #include <qwt_symbol.h>
    10. #include <qwt_plot_zoomer.h>
    11.  
    12. MainWindow::MainWindow(QWidget *parent)
    13. : QMainWindow(parent)
    14. {
    15. QToolBar* tb = this->addToolBar("");
    16. tb->addAction("Zoom1", this, SLOT(zoom1()));
    17. tb->addAction("Zoom2", this, SLOT(zoom2()));
    18. tb->addAction("Zoom3", this, SLOT(zoom3()));
    19. tb->addAction("Zoom4", this, SLOT(zoom4()));
    20. tb->addAction("Zoom5", this, SLOT(zoom5()));
    21. tb->addAction("Zoom6", this, SLOT(zoom6()));
    22.  
    23. this->plot = new QwtPlot(this);
    24. plot->setFixedSize(800, 600);
    25.  
    26. this->zoomer = new QwtPlotZoomer(this->plot->canvas());
    27.  
    28. this->addCurve();
    29. this->addMarkers();
    30.  
    31. this->zoomer->setZoomBase();;
    32. this->setCentralWidget(this->plot);
    33. }
    34.  
    35. MainWindow::~MainWindow()
    36. {
    37. }
    38.  
    39. void MainWindow::zoom1( void )
    40. {
    41. this->zoomer->zoom(QRectF(QPointF(7262.49, 7256.79), QSizeF(15.8157, 29.976)));
    42. }
    43.  
    44. void MainWindow::zoom2( void )
    45. {
    46. this->zoomer->zoom(QRectF(QPointF(11794, 11794.6), QSizeF(12.9803, 12.4409)));
    47. }
    48.  
    49. void MainWindow::zoom3( void )
    50. {
    51. this->zoomer->zoom(QRectF(QPointF(9975.49, 9973.82), QSizeF(1.379,4.97203)));
    52. }
    53.  
    54. void MainWindow::zoom4( void )
    55. {
    56. this->zoomer->zoom(QRectF(QPointF(9555.91, 9556.03), QSizeF(0.2, 0.3525673)));
    57. }
    58.  
    59. void MainWindow::zoom5( void )
    60. {
    61. this->zoomer->zoom(QRectF(QPointF(7931.51, 7931.44), QSizeF(0.951209, 0.998621)));
    62. }
    63.  
    64. void MainWindow::zoom6( void )
    65. {
    66. this->zoomer->zoom(QRectF(QPointF(3357.88, 15976.8), QSizeF(142.687, 550.418)));
    67. }
    68.  
    69. void MainWindow::addCurve( void )
    70. {
    71. int count = 20000;
    72.  
    73. for(int i = 0; i < count; ++i)
    74. {
    75. this->x.append(i);
    76. this->y.append(i);
    77. }
    78.  
    79. QwtPlotCurve* curve = new QwtPlotCurve();
    80. curve->setData(this->x.constBegin(), this->y.constBegin(), this->x.size());
    81. curve->attach(this->plot);
    82. }
    83.  
    84. void MainWindow::addMarkers( void )
    85. {
    86. int count = 5000;
    87. int step = this->x.size()/count;
    88.  
    89. for(int i = 0; i < count; ++i)
    90. {
    91. int x = i*step;
    92. int y = this->y[x];
    93.  
    94. m->setSymbol(QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::red), QPen(Qt::red), QSize(5,5)));
    95. m->setValue(x, y);
    96. m->setLabel(QString("%1x%2").arg(x).arg(y));
    97.  
    98. m->attach(this->plot);
    99. }
    100. }
    To copy to clipboard, switch view to plain text mode 

    Any suggestions what is a cause of this behaviour?
    Last edited by Spitfire; 3rd November 2011 at 12:01.

  7. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    First of all simplify your code:

    a) throw away the zoomer and set the scales to an area, where you have problems using: QwtPlot::setAxisScale
    b) attach only one type of plot item ( curve or markers )

    • After you have eliminated one type of plot item: which one is the reason for the problem ( when only markers are left remove your vectors too ) ?
    • What happens when using "-graphicssystem raster" on your linux box ?
    • What exactly is wrong in your screenshot: the lines, the text labels, the symbols or whatever do you mean by aliens ? Didn't check your code in detail, but as the markers have different coordinates as the curve points - is it about the text labels ?


    When you have sorted these thing s out, we can continue to debug the details,

    Uwe

  8. #7
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    Hey Uve,

    From what I see the problem seems to be somewhere around QwtSymbol::Ellipse.
    When I change it to rect, everything is fine.

    But going back:
    - using '-graphicssystem raster' on linux box doesn't seem to make any difference - everything is still fine.
    - I've simplified the code to have just single marker:
    Qt Code:
    1. //mainwindow.cpp
    2. #include "mainwindow.h"
    3.  
    4. #include <QToolBar>
    5. #include <QDebug>
    6.  
    7. #include <qwt_plot.h>
    8. #include <qwt_plot_marker.h>
    9. #include <qwt_symbol.h>
    10.  
    11. MainWindow::MainWindow(QWidget *parent)
    12. : QMainWindow(parent)
    13. {
    14. QToolBar* tb = this->addToolBar("");
    15. tb->addAction("Zoom (~7262x7256)", this, SLOT(zoom()));
    16. tb->addAction("Reset", this, SLOT(reset()));
    17.  
    18. this->plot = new QwtPlot(this);
    19. plot->setFixedSize(800, 600);
    20. this->setCentralWidget(this->plot);
    21.  
    22. this->addMarker();
    23. this->reset();
    24. }
    25.  
    26. MainWindow::~MainWindow()
    27. {
    28. }
    29.  
    30. void MainWindow::zoom( void )
    31. {
    32. this->plot->setAxisScale(QwtPlot::xBottom, 7262.49, 7262.49+15.8157);
    33. this->plot->setAxisScale(QwtPlot::yLeft, 7256.79, 7256.79+29.976);
    34. this->plot->replot();
    35. }
    36.  
    37. void MainWindow::reset( void )
    38. {
    39. this->plot->setAxisScale(QwtPlot::xBottom, 0, 10000);
    40. this->plot->setAxisScale(QwtPlot::yLeft, 0, 10000);
    41. this->plot->replot();
    42. }
    43.  
    44. void MainWindow::addMarker( void )
    45. {
    46. m->setSymbol(QwtSymbol(QwtSymbol::Ellipse, QBrush(Qt::red), QPen(Qt::red), QSize(5,5)));
    47. m->setValue(280, 280);
    48. m->setLabel(QString("%1x%2").arg(280).arg(280));
    49. m->attach(this->plot);
    50. }
    To copy to clipboard, switch view to plain text mode 
    The scale is set to 0-10000 on both X and Y axis.
    There's only one marker at 280x280 with some text (to distinguish it from the alien one).
    Zoom button zooms into certain area: top left: 7262.49x7256.79 size: 15.8157x29.976.
    When you zoom in you can see marker symbol in a place where it should be nothing.

    Here's a sceenshot before zooming, you can see a marker with some text at 280x280 position:
    actual.jpg
    And here's a screenshot after zooming, you can see a marker with no text at around 7274x7272.
    alien.jpg

    I think that for some reason (bug in Qwt/Qt? int overflow?) Ellipse symbol is drawn in wrong place.
    I'm testing it with Qwt 5.2.0 (Qt 4.6.3, w7 64bit) and this particular point I've chosen will probably fail to show the problem with different version but it happens with other versions as well for different points.

    So any ideas why this symbol appears where it should not?

  9. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    Next step is to start your debugger ( or add some debug statements ) and check the rectangle ( this is in widget coordinates ) in QwtPainter::drawEllipse.

    What are the coordinates ?

    Uwe

  10. #9
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    Done that some time ago but it seems fine to me, rectangle is far outside visible area.:

    Drawing Ellipse: QRect(-327141,131369 4x4) (reported by QwtPainter::drawEllipse() ).


    In fact I've done much simpler example using Qt only:
    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent *)
    2. {
    3. QPainter p(this);
    4. p.setBrush(Qt::red);
    5. p.drawEllipse(QPointF(-327650.0, 131100.0), 10.0, 10.0);
    6. }
    To copy to clipboard, switch view to plain text mode 

    This will draw black (!) ellipse around top left corner of the window.

    Qt bug?

  11. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    Well then change the implementation of QwtPlotMarker::draw this way:

    Qt Code:
    1. void QwtPlotMarker::draw( QPainter *painter,
    2. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    3. const QRectF &canvasRect ) const
    4. {
    5. const QPointF pos( xMap.transform( d_data->xValue ),
    6. yMap.transform( d_data->yValue ) );
    7.  
    8. // draw lines
    9.  
    10. drawLines( painter, canvasRect, pos );
    11.  
    12. if ( canvasRect.contains( pos ) )
    13. {
    14. // draw symbol
    15. if ( d_data->symbol &&
    16. ( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
    17. {
    18. d_data->symbol->drawSymbol( painter, pos );
    19. }
    20.  
    21. drawLabel( painter, canvasRect, pos );
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

  12. The following user says thank you to Uwe for this useful post:

    Spitfire (3rd November 2011)

  13. #11
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Random markers from nowhere.

    I may do that.
    Thanks for suggestion.

    I'm surprised to find something like that.
    Anyway, I know what to do now, At least I can proceed further

    Thanks again guys!

Similar Threads

  1. Replies: 1
    Last Post: 10th May 2011, 07:29
  2. how to set markers below a slider in qt
    By qt_user in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2010, 08:02
  3. Markers are not removed from QwtPlot
    By MuzZviman in forum Qwt
    Replies: 1
    Last Post: 3rd June 2010, 08:25
  4. Replies: 1
    Last Post: 7th April 2010, 17:26
  5. qscintilla and markers
    By sawerset in forum Qt Programming
    Replies: 0
    Last Post: 17th February 2009, 22:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.