Menu

#83 patch: add rect curve to render rectangular intervals

open
patch (3)
5
2024-07-18
2023-05-11
No

Follow-up on ticket #82 to split the changes.

Changes in this patch:
* adds QwtPlotRectCurve - renders a series of rectangles.
* adds playground/plotdemo

Motivation: display large number of rectangles. Comparing to QwtPlotShapeItem renders / scales faster for large numbers of small rectangles.

Example code (python) below. Resizing the corresponding plots feels about x2/x3 faster on plot1.

N = 100000

def make_rect():
    return [
        QRectF(x, y, w, 1.0)
        for x, w, y in zip(
            numpy.random.uniform(0, 100, N),
            numpy.random.uniform(0, 0.01, N),
            numpy.random.choice(4, N)
        )
    ]


def make_plot1():
    plot1 = QwtPlot()
    plot1.resize(1200, 800)
    plot1.show()

    s = QwtPlotRectSeries(title="abc")
    s.setBrush(Qt.red)
    s.setPen(Qt.darkRed)
    s.setSamples(make_rect())
    s.attach(plot1)

    return plot1


def make_plot2():
    plot2 = QwtPlot()
    plot2.resize(1200, 800)
    plot2.show()

    shape = QPainterPath()
    for rect in make_rect():
        shape.addRect(rect)

    s = QwtPlotShapeItem(title="abc")
    s.setBrush(Qt.red)
    s.setPen(Qt.darkRed)
    s.setShape(shape)
    s.attach(plot2)

    return plot2
1 Attachments

Related

Patches: #83

Discussion

  • Anonymous

    Anonymous - 2023-05-23

    Hi Uwe.
    Any comments or decisions on suggested patch?

    Thanks,
    Gregory.

     
  • Anonymous

    Anonymous - 2023-06-26

    Hi.
    Any go/no-go decisions on this patch?

    Thanks,
    Gregory.

     
  • Uwe Rathmann

    Uwe Rathmann - 2023-06-26

    It can be expected, that a list of rectangles will be faster than a QPainterPath with the same rectangles . The painter path stores moveTo/lineTo sequences finding out that its subpaths are actually rectangles while painting. This should be a factor for many rectangles - needs to be quantified.

    But it would also be possible to introduce:

    QwtPlotShapeItem::setShape( const QVector< QRectF >& );
    

    Then the shape item would know, that its path is made of rectangles and could chose a faster implementation. that should be pretty close to the performance one gets with your code.

    The same could be done for lines ...

     
  • Anonymous

    Anonymous - 2023-06-26

    Wouldn't that defeat the whole idea behind QwtPlotShapeItem?
    QPainterPath stored by QwtPlotShapeItem itself does not seem to provide alot of introspection information, so once converted to a QPainterPath it would be cumbersome to reproduce the individual elements.
    Do you suggest to store a vector of rectangles in QwtPlotShapeItem instead?

     
  • Uwe Rathmann

    Uwe Rathmann - 2023-06-26

    The information would be stored in an extra flag in QwtPlotShapeItem::PrivateData.
    When using setShape( const QVector< QRectF >& ) it would be set immediately.

    It should also be not that hard to identify a list of rectangles from a QPainterPath - guess a loop with ~20 lines of code. This needs to be done whenever the path changes but not each time it is rendered.

    Didn't check the implementation of QPainterPath, but I would expect to find seqeuences of 1 MoveTo and 4 lineTo elements, with certain requirements for the x/y coordinates. Guess there are no variations beside having the points clockwise or v.v. - or maybe having point duplicates.

    Of course a QPainterPath rectangle needs more memory than a QRectF ( 5 * 24 vs 4 * 8 ? ) and you always have to copy the rectangles while your implementation allows to iterate over any type of data structure.

    There are pros and cons for both directions.

     
  • Anonymous

    Anonymous - 2024-07-06

    Hi.

    It appears that the objections to this patch are based on the premise that similar features could be implemented over QPainterPath. But since there are no existing / planned optimizations for generic qpainterpath, there is no immediate substitution...

    Any drop/accept verdict on this patch?

    Regards,
    Gregory.

     
  • Uwe Rathmann

    Uwe Rathmann - 2024-07-18

    Please contact me by Email for discussing the direction of this feature.

     
    • Gregory Shklover

      Which email address should I use?

      On Thu, 18 Jul 2024 at 10:56, Uwe Rathmann rathmann@users.sourceforge.net
      wrote:

      Please contact me by Email for discussing the direction of this feature.

      [patches:#83] https://sourceforge.net/p/qwt/patches/83/ patch: add rect
      curve to render rectangular intervals

      Status: open
      Group:
      Labels: patch
      Created: Thu May 11, 2023 01:35 PM UTC by Gregory Shklover
      Last Updated: Sat Jul 06, 2024 06:59 AM UTC
      Owner: Uwe Rathmann
      Attachments:

      Follow-up on ticket #82 to split the changes.

      Changes in this patch:
      * adds QwtPlotRectCurve - renders a series of rectangles.
      * adds playground/plotdemo

      Motivation: display large number of rectangles. Comparing to
      QwtPlotShapeItem renders / scales faster for large numbers of small
      rectangles.

      Example code (python) below. Resizing the corresponding plots feels about
      x2/x3 faster on plot1.

      N = 100000
      def make_rect(): return [ QRectF(x, y, w, 1.0) for x, w, y in zip( numpy.random.uniform(0, 100, N), numpy.random.uniform(0, 0.01, N), numpy.random.choice(4, N) ) ]

      def make_plot1(): plot1 = QwtPlot() plot1.resize(1200, 800) plot1.show()
      s = QwtPlotRectSeries(title="abc") s.setBrush(Qt.red) s.setPen(Qt.darkRed) s.setSamples(make_rect()) s.attach(plot1)
      return plot1

      def make_plot2(): plot2 = QwtPlot() plot2.resize(1200, 800) plot2.show()
      shape = QPainterPath() for rect in make_rect(): shape.addRect(rect)
      s = QwtPlotShapeItem(title="abc") s.setBrush(Qt.red) s.setPen(Qt.darkRed) s.setShape(shape) s.attach(plot2)
      return plot2


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/qwt/patches/83/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Patches: #83

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.