Skip to content

SAC: add getInliers, getModel, getModelCoefficients to avoid copying data#6304

Merged
mvieth merged 5 commits into
PointCloudLibrary:masterfrom
kai-waang:const-ref-in-sac
Jul 10, 2025
Merged

SAC: add getInliers, getModel, getModelCoefficients to avoid copying data#6304
mvieth merged 5 commits into
PointCloudLibrary:masterfrom
kai-waang:const-ref-in-sac

Conversation

@kai-waang

Copy link
Copy Markdown
Contributor

Adding new methods to SampleConsensus so getInliers, getModel and getModelCoefficients return a const reference.
Usages within PCL has been replaced.

Adding new methods to `SampleConsensus` so getInliers, getModel and getModelCoefficients return a const reference.
@mvieth mvieth added changelog: enhancement Meta-information for changelog generation module: sample_consensus labels Jul 8, 2025

@mvieth mvieth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for implementing this! I have a few comments.

Comment thread sample_consensus/include/pcl/sample_consensus/sac.h Outdated
Comment thread sample_consensus/include/pcl/sample_consensus/sac.h Outdated
Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com>
@kai-waang

Copy link
Copy Markdown
Contributor Author

Thanks for implementing this! I have a few comments.

Thanks a lot, I have applied the suggestions.

@larshg

larshg commented Jul 8, 2025

Copy link
Copy Markdown
Contributor

Thanks for implementing this! I have a few comments.

Thanks a lot, I have applied the suggestions.

You'll need to review the other places to changed them as well - adding & and consts.

Co-authored-by: Markus Vieth <39675748+mvieth@users.noreply.github.com>
larshg
larshg previously approved these changes Jul 10, 2025
@larshg larshg requested a review from Copilot July 10, 2025 12:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors SampleConsensus APIs to return const references for inliers, model, and coefficients, and updates all internal call sites to use these new getters.

  • Introduced const & overloads for getInliers(), getModel(), and getModelCoefficients() in sac.h
  • Updated segmentation and registration modules to use return-value getters instead of out-parameter calls
  • Removed redundant variable declarations and replaced sac.get*() calls accordingly

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/sac_segmentation_plane.cpp Replaced out-param calls with returned values for inliers/coeff
segmentation/include/pcl/segmentation/impl/sac_segmentation.hpp Updated .segment() to assign from return‐value getters
segmentation/include/pcl/segmentation/impl/cpc_segmentation.hpp Switched to return‐value getters and direct assignment
sample_consensus/include/pcl/sample_consensus/sac.h Added const-reference overloads for getModel, getInliers(), getModelCoefficients()
registration/include/pcl/registration/impl/correspondence_rejection_sample_consensus_2d.hpp Used const auto& and return‐value getters for inliers/coeffs
registration/include/pcl/registration/impl/correspondence_rejection_sample_consensus.hpp Same updates as in 2D version
Comments suppressed due to low confidence (1)

sample_consensus/include/pcl/sample_consensus/sac.h:310

  • Add unit tests covering the new const‐reference getters (getInliers(), getModel(), getModelCoefficients()) to validate that they return the correct data and to prevent future regressions.
      inline const Indices&

Comment thread tools/sac_segmentation_plane.cpp
Comment thread tools/sac_segmentation_plane.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@kai-waang

Copy link
Copy Markdown
Contributor Author

Sorry for not carefully checking Copilot's suggestions; the last commit has been reverted.

@mvieth mvieth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@larshg larshg added this to the pcl-1.15.1 milestone Jul 10, 2025
@mvieth mvieth merged commit ef04ffa into PointCloudLibrary:master Jul 10, 2025
13 checks passed
@kai-waang kai-waang deleted the const-ref-in-sac branch July 11, 2025 05:04
@mvieth mvieth changed the title Fixing #6239 SAC: add getInliers, getModel, getModelCoefficients to avoid copying data Jul 30, 2025
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: sample_consensus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[sample_consensus] Sac::getInliers should return the results as a const reference instead of to a parameter

4 participants