-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add automatic simplification to mask clipping paths when exporting layouts #57703
Conversation
Add QgsAbstractGeometry::simplifyByDistance, which is a direct port of GEOS Douglas Peucker algorithm. This is a trivial algorithm to implement, and we benefit from avoiding the conversion to/from GEOS geometries.
And API mechanism to propagate these from layout exports down to the render context Gives us a place to specify fine-tuned control over masking settings for map renders
This results in much smaller output file sizes, and files which load much quicker in PDF viewers/editors Refs qgis#50734 Refs qgis#54788
multigeometries to separate geometries in the vector This gives us more scope to optimise which geometries we want to use when rendering objects within a particular part of the map
Move the geometry repair to when we add it to the render context, instead of every time we retrieve it
By simplifying line strings PRIOR to buffering, we get a significant performance bump, as we're not asking GEOS to buffer excessively detailed linestrings and then immediately discarding most of the vertices.
e1ef597
to
aa8e5d9
Compare
aa8e5d9
to
cded741
Compare
@troopa81 can I get a review of this? |
Yes, I'll review it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should not treat mask like vector and reuse QgsLayoutRenderContext::simplifyMethod. Did you consider it?
Why simplifying both when painting and when merging clip path ?
std::unique_ptr< QgsAbstractGeometry > buffered; | ||
if ( mSimplifyTolerance > 0 ) | ||
{ | ||
// For performance, we apply a lower level of simplification to the line BEFORE doing the buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that it doesn't improve this issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you retest please? There's no way the gridded/pixelated mask output could be exported by this branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there's a couple of reasons why it needs to be different:
The native simplification method is extremely fast. We want to simplify prior to the union or the GEOS union is very slow. But the output of the union can add additional vertices (when masks overlap and GEOS fully nodes them), which we can also strip away (with the cheap simplify call) and ensure smallest possible output file size. |
Thanks for the review @troopa81 ! It's much appreciated! |
When the (currently non-default) geometry backend is used for selective masking (see #57623), we now apply a conservative amount of simplification to the clipping paths when exporting layouts to pdf /svg.
This results in much smaller file sizes, and PDFs /SVGs which are much faster to load in viewers/editors.
Refs #50734
Refs #54788
(I think we could safely make the simplification factor more aggressive, but I've opted for an initially conservative amount while we discuss the rest of these changes)