Results 1 to 8 of 8

Thread: Fill mode using QPainter

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Fill mode using QPainter

    Hi,

    I am plotting a set of curves next to one another, amplitude vs. time (amplitudes are measured at different time), where time is in y axis and amplitude is in x axis.

    I need to fill all curves whose amplitudes are over a certain amplitude, or those whose amplitudes are less than a certain amplitude.

    In the attached example, I only fill positive amplitude, but eventually I need be able to fill negative amplitude too..

    How can I effectively do this with good performance? QPainter::setClipPath is extremely slow...

    Thanks
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Fill mode using QPainter

    Can anyone give a suggestion? Let's say I just need to draw one curve, where I need to fill the area whose amplitude are greater than a certain value...

    Thanks

  3. #3
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Fill mode using QPainter

    Have you tried QPainter::drawPolyon()?
    And how slow is slow? How many values does a typical curve have?

  4. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Fill mode using QPainter

    Quote Originally Posted by spud View Post
    Have you tried QPainter::drawPolyon()?
    And how slow is slow? How many values does a typical curve have?
    That is what I am using. To fill the area, I need to clip the painter using QPainter::setClipPath, which in turn needs to call QPainterPath::addPolygon. In my test, I have 512 curves with 370 points in each curve, this takes 2 to 5 seconds to plot. The real data will have more curves and more points...

    I have seen no visual delay in plotting much larger data from other software, so I guess I am doing it wrong....
    Last edited by lni; 23rd March 2009 at 14:46.

  5. #5
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Fill mode using QPainter

    If you can avoid using a clip path, you will certainly be faster, but plotting 200.000 points is going to be slow however you do it. You have to reduce the complexity somehow, or cache rendered pixmaps.

  6. #6
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Fill mode using QPainter

    Quote Originally Posted by spud View Post
    If you can avoid using a clip path, you will certainly be faster, but plotting 200.000 points is going to be slow however you do it. You have to reduce the complexity somehow, or cache rendered pixmaps.
    Then how do you fill the area whose amplitudes are larger than the given value? It may be slow, but I am comparing similar software that has more points than my test data, and they are much faster...

  7. #7
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Fill mode using QPainter

    This code is performant enough for me with up to 10.000 points:
    Qt Code:
    1. class Plot : public QWidget
    2. {
    3. public:
    4. Plot()
    5. {
    6. for(int x=0;x<POINT_COUNT;x++)
    7. data[x] = QPointF(qreal(x)/POINT_COUNT, sin(x/20.));
    8. data[POINT_COUNT-1]=QPointF(1, 0);
    9. }
    10. void paintEvent(QPaintEvent*)
    11. {
    12. QPainter painter(this);
    13. painter.setRenderHint(QPainter::Antialiasing);
    14. painter.translate(0, height()/2);
    15. painter.scale(width(), height()/2);
    16. painter.setPen(Qt::darkGreen);
    17. painter.setBrush(Qt::green);
    18. painter.drawPolygon(data, POINT_COUNT);
    19. }
    20. static const int POINT_COUNT = 1000;
    21. QPointF data[POINT_COUNT];
    22. };
    To copy to clipboard, switch view to plain text mode 
    It will be faster without antialiasing of course.
    If you want to speed it up more, you could use multiple threads that paint on QImages which are combined, or you could try painting on an OpenGL window.
    But first of all I would try reducing complexity. How large is your rendering target? You don't need to use more than one point every two pixels or so.

  8. #8
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Fill mode using QPainter

    Thanks!

    The requirements are to fill the area whose amplitudes are bigger than a certain value, for instance, in your sine curve example, only fill the area whose amplitudes are bigger than 0.7, not to fill the entire polygon...

    I didn't specify render hint, so the default hint is used which I think should be a faster one...

    The data set has dimension of 256 x 370, the plot widget has a size of 800 x 800...

    There is no multi-thread involved because the software I am comparing to doesn't use multi-thread...

Similar Threads

  1. Not able to execute in Release Mode
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 18th March 2009, 11:58
  2. [qt4,win,g++] QPainter on a QGLWidget
    By jh in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2008, 06:29
  3. Replies: 2
    Last Post: 22nd July 2007, 19:21
  4. qodbc driver not loaded error in release mode
    By mandal in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2006, 09:42
  5. Replies: 7
    Last Post: 20th March 2006, 20:03

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
  •  
Qt is a trademark of The Qt Company.