Skip to content

add explicit instantiations to transformation estimation LM and one to ICP #6258

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

Merged

Conversation

themightyoarfish
Copy link
Contributor

@themightyoarfish themightyoarfish commented Mar 27, 2025

based on #5894
this class takes a lot of time to instantiate in my program.

@mvieth
Copy link
Member

mvieth commented Mar 30, 2025

Hi, why did you add the change in icp.cpp to this pull request? It seems unrelated to the other changes and does not even have any effect without a corresponding update in icp.h.
Please also have a look at the formatting of the files. The formatting check currently does not pass.

@mvieth mvieth added module: registration changelog: enhancement Meta-information for changelog generation labels Mar 30, 2025
@themightyoarfish
Copy link
Contributor Author

themightyoarfish commented Mar 30, 2025

Will fix formatting.

I think using ICP with PointNormal as the target type is not so unusual, you need it for using the Point-to-Plane error. In my work, i often have normals for the target, as a 3D model is available. Hence why i added the instantiation. missed the change in the header.

@mvieth
Copy link
Member

mvieth commented Mar 31, 2025

Can you try changing this:

int k = tree_->nearestKSearch(cloud, index, 1, indices, distances);

to
int k = tree_->nearestKSearchT(cloud[index], 1, indices, distances); ?
That should hopefully solve the build error on Windows.

@themightyoarfish
Copy link
Contributor Author

done in cf13771

@mvieth
Copy link
Member

mvieth commented Apr 1, 2025

You missed adding the T in nearestKSearchT. When using nearestKSearchT, the first argument can be any point type.

@themightyoarfish themightyoarfish force-pushed the explicit-instantiations branch from 86308e8 to 2a04453 Compare April 1, 2025 12:50
Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com>
@mvieth
Copy link
Member

mvieth commented Apr 12, 2025

@themightyoarfish There are still (additional) build errors on Windows. Please either find solutions for them until all checks are successful, or remove the explicit instantiation of IterativeClosestPoint<pcl::PointXYZI, pcl::PointNormal> from this pull request. I currently do not have the time to offer detailed suggestions how to fix the errors.

@themightyoarfish
Copy link
Contributor Author

It looks like the CI passed now.

@@ -462,5 +462,6 @@ class IterativeClosestPointWithNormals
#if !defined(PCL_NO_PRECOMPILE) && !defined(PCL_REGISTRATION_ICP_CPP_)
extern template class pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZ>;
extern template class pcl::IterativeClosestPoint<pcl::PointXYZI, pcl::PointXYZI>;
extern template class pcl::IterativeClosestPoint<pcl::PointXYZI, pcl::PointNormal>;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
extern template class pcl::IterativeClosestPoint<pcl::PointXYZI, pcl::PointNormal>;
extern template class pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointNormal>;

To match the instantiation in icp.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

made all match in 98bb945

Copy link
Member

Choose a reason for hiding this comment

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

To be honest, I am against adding instantiations for both pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointNormal> and pcl::IterativeClosestPoint<pcl::PointXYZI, pcl::PointNormal>. I would for now only add the former (PointXYZ), but not the latter (PointXYZI). Hopefully you agree with me that the number of explicit template instantiations should be kept low, otherwise we increase both the build time of PCL as well as the binary size of PCL (both affecting everyone, regardless whether they use the instantiations or not). I see your point that people might use PointXYZ and PointNormal for ICP with point-to-plane estimation because only the target cloud needs normals, even though I believe that people using different point types for source and target clouds is rare. So, with PointXYZ for source and PointNormal for target, both point types have the fewest fields necessary to still work with point-to-plane ICP (no intensity, rgb, labels, etc necessary). But if we add pcl::IterativeClosestPoint<pcl::PointXYZI, pcl::PointNormal>, we could just as well also add pcl::IterativeClosestPoint<pcl::PointXYZL, pcl::PointNormal> and pcl::IterativeClosestPoint<pcl::PointXYZRGB, pcl::PointNormal> and pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointXYZINormal> and pcl::IterativeClosestPoint<pcl::PointXYZI, pcl::PointXYZINormal> and so on. I think only for pcl::IterativeClosestPoint<pcl::PointXYZ, pcl::PointNormal> there is a good reason to have it. But for all the other source type/target type combinations (where source type != target type), there is no real reason to have some but not others, and overall I think these are not used by enough people to justify adding explicit instantiations for them.

As a side note, I think it could be an option to add an explicit instantiation for any point types you like in your own project, then reuse that. That way, you do not have to recompile the heavy instantiations when you rebuild other parts of your project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah ok i have removed the XYZI-PointNormal instantiation.

@themightyoarfish themightyoarfish force-pushed the explicit-instantiations branch from 98bb945 to 29a2afd Compare April 14, 2025 12:28
@themightyoarfish themightyoarfish changed the title add explicit instantiation to transformation estimation LM add explicit instantiations to transformation estimation LM and one to ICP Apr 14, 2025
Copy link
Member

@mvieth mvieth 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 to me now. Thanks for bearing with my change requests 🙂

@mvieth mvieth added this to the pcl-1.15.1 milestone Apr 14, 2025
@mvieth mvieth merged commit da64bf9 into PointCloudLibrary:master Apr 15, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: enhancement Meta-information for changelog generation module: registration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants