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

use faster unit quaternion rotation #625

Closed

Conversation

4ngry
Copy link
Contributor

@4ngry 4ngry commented Sep 24, 2020

It seems that original ceres::UnitQuaternionRotatePoint is based on idea: convert to rotation matrix, then rotate. It seems quite inefficient, since obtained rotation matrix is not cached anywhere and had to be recomputed each time UnitQuaternionRotatePoint is called.

Updated code uses ideas from here:
https://fgiesen.wordpress.com/2019/02/09/rotating-a-single-vector-using-a-quaternion/
The same code also implemented in Eigen v.3.3.7 , under Eigen::Quaternion::_transformVector().

The code was tested under context of Structure-From-Motion tasks inside bundle adjustment cost functions with COLMAP code base, and behaves quite well.

I did not measure the execution time, but when by counting multiply-adds original ceres::UnitQuaternionRotatePoint has around 24(21 if not counting negations) multiplications and 18 additions, while proposed one has 15 multiplications and 15 additions.

@sandwichmaker
Copy link
Contributor

@4ngry thank you for the patch. Two things.

  1. We do not accept patches on github yet. Please follow the instructions at http://ceres-solver.org/contributing.html
  2. Faster has to be backed up with a benchmark :)

@4ngry
Copy link
Contributor Author

4ngry commented Sep 24, 2020

  1. Followed instructions with Gerrrit
  2. Will come with syntetic benchmark for unit quaternion rotation of vector soon.

@4ngry
Copy link
Contributor Author

4ngry commented Sep 29, 2020

Benchmark code and visualization is here https://quick-bench.com/q/RgVitjKbGLZMszyG9ivMFzvo0CE
Dummy times used for random quaternion and vector generation should be subtracted from total time, to compare existent function with proposed one, but it is clearly that in case of double performance is around 2x better. For float not that much, but still valuable. I will post the benchmark code via Gerrit system also, as Samir suggested.

@4ngry 4ngry closed this Nov 19, 2020
@4ngry
Copy link
Contributor Author

4ngry commented Nov 19, 2020

Seems that merged now.

@sandwichmaker
Copy link
Contributor

sandwichmaker commented Nov 19, 2020 via email

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.

None yet

2 participants