patch: add rect curve to render rectangular intervals
Brought to you by:
rathmann
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
Anonymous
Hi Uwe.
Any comments or decisions on suggested patch?
Thanks,
Gregory.
Hi.
Any go/no-go decisions on this patch?
Thanks,
Gregory.
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:
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 ...
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?
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.
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.
Please contact me by Email for discussing the direction of this feature.
Which email address should I use?
On Thu, 18 Jul 2024 at 10:56, Uwe Rathmann rathmann@users.sourceforge.net
wrote:
Related
Patches: #83