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

Refactoring and Bugfix of NDT #4180

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

koide3
Copy link
Contributor

@koide3 koide3 commented Jun 12, 2020

@kunaltyagi
Sorry for being late to open this PR. I refactored the NDT code according to #4135 and took a look at the suspicious code mentioned at #3832.

Refactoring #4135 (review)

  • PCL_NO_COMPILE condition check is added to ndt.cpp
  • Unneeded codes are removed
  • I left the arguments of updateIntervalMT and trialValueSelectionMT as they are because these methods have different in/out argument combinations, and putting them in a struct would hide this information
  • h_ang_* are concatenated into one matrix for simplicity and Eigen's SSE optimization (it brings about 1% speedup)
  • Parentheses are removed from return statements
  • point_gradient is renamed to point_jacobian
  • Transformation vector p is renamed to transform
  • Typo fixed

All the above modifications don't change the behavior of NDT, and the registration result will be exactly the same as before refactoring.

Bugfix #3832 (comment)
(step_max - step_min) > 0 must be (step_max - step_min) < 0 because this code is intended to check the validity of the range. As @atom2003 pointed out, (step_max - step_min) > 0 is always true, and this prevents the step length calculation being performed. This bug affects the registration accuracy in particular when we set a small transformation_epsilon for fine registration.

After resolving this bug, the fitness score of the registration result of the unit test (test_ndt.cpp) is slightly improved (before: 5.05433e-05, after: 4.68033e-05).

I also confirmed the accuracy improvement on my own dataset. The following figures show sensor trajectories estimated by frame-by-frame NDT registration, and the one before the bugfix has a large drift.

After Bugfix
after1

Before Bugfix
before1

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Adding notes of the notable non-variable-name-change

registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
registration/src/ndt.cpp Outdated Show resolved Hide resolved
@@ -440,21 +438,16 @@ namespace pcl
*
* The precomputed angular derivatives for the jacobian of a transformation vector, Equation 6.19 [Magnusson 2009].
*/
Eigen::Vector3d j_ang_a_, j_ang_b_, j_ang_c_, j_ang_d_, j_ang_e_, j_ang_f_, j_ang_g_, j_ang_h_;
Eigen::Matrix<double, 8, 4> angular_jacobian_;
Copy link
Member

@kunaltyagi kunaltyagi Jun 12, 2020

Choose a reason for hiding this comment

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

Note: 3D vectors changed to 4D vectors. ABI breakage here

@kunaltyagi kunaltyagi added module: registration needs: code review Specify why not closed/merged yet labels Jun 12, 2020
@kunaltyagi
Copy link
Member

Should we separate the bug fix (the > -> <) in order to release the fix in 1.11.1? Due to ABI and public interface deprecation, this patch is scheduled for at least 1.12.0. This is not needed and we can just merge this entire PR together.

@kunaltyagi kunaltyagi added the needs: feedback Specify why not closed/merged yet label Jun 12, 2020
@koide3
Copy link
Contributor Author

koide3 commented Jun 13, 2020

Should we separate the bug fix (the > -> <) in order to release the fix in 1.11.1?

I agree. It would be nice to merge the bug fix first because it brings significant accuracy improment. Should I open another PR for the bugfix?

@kunaltyagi kunaltyagi added this to the pcl-1.12.0 milestone Jun 13, 2020
@kunaltyagi kunaltyagi removed the needs: feedback Specify why not closed/merged yet label Jun 13, 2020
@kunaltyagi kunaltyagi added the changelog: ABI break Meta-information for changelog generation label Jun 13, 2020
rsasaki0109 pushed a commit to rsasaki0109/ndt_omp_ros2 that referenced this pull request Jun 26, 2020
@kunaltyagi kunaltyagi added needs: more work Specify why not closed/merged yet and removed needs: code review Specify why not closed/merged yet labels Jul 2, 2020
Copy link
Member

@SergioRAgostinho SergioRAgostinho left a comment

Choose a reason for hiding this comment

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

Thank you for the clean-up.
Edit: looks like we need a rebase though

@kunaltyagi kunaltyagi self-requested a review July 3, 2020 09:39
@koide3
Copy link
Contributor Author

koide3 commented Jul 3, 2020

I rabased and there should not be conflicts now.
Thanks for reviewing.

@koide3
Copy link
Contributor Author

koide3 commented Jul 3, 2020

Sorry, it seems the commit was contaminated with a wrong branch. I'll revert it.

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Welp. I reviewed some before looking at what I was reviewing 👀. You can use this in the other PR though 😆

test/registration/test_ndt_omp.cpp Outdated Show resolved Hide resolved
test/registration/test_ndt_omp.cpp Outdated Show resolved Hide resolved
filters/include/pcl/filters/impl/voxel_grid_covariance.hpp Outdated Show resolved Hide resolved
filters/include/pcl/filters/impl/voxel_grid_covariance.hpp Outdated Show resolved Hide resolved
@koide3 koide3 force-pushed the ndt-refactoring branch 2 times, most recently from 09863c3 to 88c5b89 Compare July 6, 2020 02:46
@koide3
Copy link
Contributor Author

koide3 commented Jul 6, 2020

Sorry, I did something wrong and did reset the branch. I'm sorry if it increases the reviewing effort...

@kunaltyagi
Copy link
Member

Is this ready for review?

@koide3
Copy link
Contributor Author

koide3 commented Jul 7, 2020

Yes, it's ready.

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Based on what you've said, you performed some benchmarking? Could you please share those results?

registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
@koide3
Copy link
Contributor Author

koide3 commented Jul 8, 2020

I found a bug in computeDerivatives() that was injected during the refactoring. I fixed it, and now the registration result is consistent with the NDT in master branch.

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Looks good otherwise. After these and CI passes, rebase and merge as needed. My bandwidth is a bit low nowadays

registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
@koide3
Copy link
Contributor Author

koide3 commented Jul 9, 2020

In computeHessian(), I found a bug same as the one in computeDerivatives(). After fixing it, I confirmed that the score, jacobian, and hessian each iteration step are exactly the same as before refactoring.

CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Just a few more places where we can put const in

registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
registration/include/pcl/registration/impl/ndt.hpp Outdated Show resolved Hide resolved
@koide3
Copy link
Contributor Author

koide3 commented Jul 12, 2020

I replaced duplicated transformation vector-matrix conversion codes with convertTransform (that had existed but not been used).

Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

Thanks for the update with const

registration/include/pcl/registration/ndt.h Show resolved Hide resolved
@kunaltyagi
Copy link
Member

Needs conflict resolution and green CI, but a go from my side

@koide3
Copy link
Contributor Author

koide3 commented Jul 14, 2020

I did rebase and squash to resolve the conflict

@SergioRAgostinho SergioRAgostinho removed the needs: more work Specify why not closed/merged yet label Jul 14, 2020
@kunaltyagi
Copy link
Member

Work on ABI breaks can now commence

@kunaltyagi kunaltyagi merged commit fcbc655 into PointCloudLibrary:master Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: ABI break Meta-information for changelog generation module: registration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants