Skip to content
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

[Improvement] Use BoundingBoxes in labeling #2852

Merged
merged 1 commit into from
Mar 7, 2016

Conversation

ahuarte47
Copy link
Contributor

Use BoundingBoxes to check faster if clipping is necessary.

Now it uses directly the geometries to check if clipping is necessary. There is a performance bottleneck with this.

@ahuarte47 ahuarte47 changed the title Use BoundingBoxes in labeling [Improvement] Use BoundingBoxes in labeling Feb 29, 2016
@ahuarte47 ahuarte47 force-pushed the Labeling_CheckBoundingBoxes branch from eb730be to d1cc22e Compare March 2, 2016 01:19
@ahuarte47
Copy link
Contributor Author

I moved the topology validation to last item to verify because "isGeosValid" is a costly method

@@ -3944,7 +3944,7 @@ QgsGeometry* QgsPalLabeling::prepareGeometry( const QgsGeometry* geometry, QgsRe
clonedGeometry.reset( geom );
}

if ( clipGeometry && !clipGeometry->contains( geom ) )
if ( clipGeometry && !clipGeometry->boundingBox().contains( geom->boundingBox() ) )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line should be left untouched. If a map is rotated then the extent geometry will be a rotated rectangle, so taking its bounding box will result in a larger extent then is actually visible. In this case we'd still need to clip. The geometryRequiresPreparation change is safe since it's already returned true if the map is rotated, but I think this second check should be left at the original version. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this previous line covers it? no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahuarte47 Sorry, I don't quite understand. The changes to geometryRequiresPreparation are fine, no issue there. But we need to make sure the test before doing the actual clipping is still applied using the geometries themselves when rotation is applied. Maybe a better replacement for line 3947 would be:

  if ( clipGeometry &&
  ( ( qgsDoubleNear( m2p.mapRotation(), 0 ) && !clipGeometry->boundingBox().contains( geom->boundingBox() ) )
    || ( !qgsDoubleNear( m2p.mapRotation(), 0 ) && !clipGeometry->contains( geom ) ) ) )

Ie if no rotation, do the optimised bounding box check, but if rotation then do the full expensive check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyalldawson sorry, I mixed the code in my mind, my apologies, you are right!

Thanks for your pacience :-)

@ahuarte47 ahuarte47 force-pushed the Labeling_CheckBoundingBoxes branch from 1b56f2b to 8bdb9e4 Compare March 6, 2016 22:43
@nyalldawson
Copy link
Collaborator

@ahuarte47 no need to apologise - I'm just happy someone is looking to speed this stuff up!

@ahuarte47
Copy link
Contributor Author

:-) thanks to you for your work. I am working in this work. I hope in right way.

@ahuarte47 ahuarte47 force-pushed the Labeling_CheckBoundingBoxes branch 2 times, most recently from ac91d8e to 2809b82 Compare March 6, 2016 23:33
Use BoundingBoxes to check faster if clipping is necessary
@ahuarte47 ahuarte47 force-pushed the Labeling_CheckBoundingBoxes branch from 2809b82 to b07bbd0 Compare March 7, 2016 00:16
@nyalldawson
Copy link
Collaborator

@ahuarte47 I noticed you're having issues with the indentation test - here's some tips getting this to pass:

Tips to prevent and resolve:

  • Enable WITH_ASTYLE in your cmake configuration to format C++ code
  • Install autopep8 (>= 1.2.1) to format python code
  • Use "scripts/astyle.sh file" to fix the now badly indented files
  • Consider using scripts/prepare-commit.sh as pre-commit hook to avoid this
    in the future (ln -s ../../scripts/prepare-commit.sh .git/hooks/pre-commit) or
    run it manually before each commit.

@ahuarte47
Copy link
Contributor Author

Thanks @nyalldawson

nyalldawson added a commit that referenced this pull request Mar 7, 2016
[Improvement] Use BoundingBoxes in labeling
@nyalldawson nyalldawson merged commit bd140a7 into qgis:master Mar 7, 2016
@ahuarte47 ahuarte47 deleted the Labeling_CheckBoundingBoxes branch March 7, 2016 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants