Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Enhancing performance drawing polygons with many holes
Forum Updated to NodeBB v4.3 + New Features

Enhancing performance drawing polygons with many holes

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alan73
    wrote on last edited by
    #1

    I'm drawing complex polygons with many vertices and holes.
    Code sample:

    QImage image;    // some image
    QPainter painter;
    painter.begin(&image);
    
    // overall region
    QPolygon polygon;
    polygon.setPoints(polyCounts, (int*)polyPoints);
    QRegion region(polygon);
    
    // cutting holes
    while ( holesCount-- > 0 )
    {
        QPolygon subtractedPolygon;
        subtractedPolygon.setPoints(holePointsCount, (int*)holePoints);
        QRegion subtractedRegion(subtractedPolygon);
        region = region.subtract(subtractedRegion);
    
      // defining next hole properties...
    }
    
    // setting clip region
    painter.setClipRegion(region, Qt::IntersectClip);
    // painting
    painter.fillRect( image.size(), Qt::red );
    

    It seems to be that main performance leaks are caused by copying points into QPolygon.
    I've tried using composition mode QPainter::CompositionMode_SourceOut: it works really faster, but I can't use it because I have to save original image contents.
    In Windows API PolyPolygon function seems to be useful in this situation:
    https://msdn.microsoft.com/en-us/library/windows/desktop/dd162818(v=vs.85).aspx
    Is there any way in Qt to improve performance in this case?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      would it possible to setup the QPolygon and QRegion outside of
      paint so it didnt have to recreate it over and over for each paint?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alan73
        wrote on last edited by
        #3

        Hi
        I use different points every rendering so it doesn't prevent from adding new points into QPolygon every painting operation.

        mrjjM 1 Reply Last reply
        0
        • A alan73

          Hi
          I use different points every rendering so it doesn't prevent from adding new points into QPolygon every painting operation.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @alan73
          ok so not really possible to cache it ?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            KeithS
            wrote on last edited by
            #5

            If you want better performance, you might want to look at using openGL.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved