Skip to content

Add error handling for insufficient correspondences in AdvancedMatching#7234

Merged
ssheorey merged 4 commits intoisl-org:mainfrom
sutatoruta:fix/insufficient-correspondences-for-tuple-test
May 27, 2025
Merged

Add error handling for insufficient correspondences in AdvancedMatching#7234
ssheorey merged 4 commits intoisl-org:mainfrom
sutatoruta:fix/insufficient-correspondences-for-tuple-test

Conversation

@sutatoruta
Copy link
Contributor

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes #
  • New feature (non-breaking change which adds functionality). Resolves #
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

The tuple test within AdvancedMatching requires at least 3 correspondences, but this requirement wasn't previously checked. This lack of validation led to an error during random number generation specifically when there were no correspondences. While having 1 or 2 correspondences did not cause this specific error, processing them is also ineffective for this test.

This PR implements the check for the minimum requirement of 3 correspondences. This prevents the error observed with 0 correspondences and also avoids unproductive processing for the ineffective cases (1 or 2 correspondences), without otherwise altering the behavior.

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

@ssheorey ssheorey requested a review from Copilot May 23, 2025 19:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a precondition check in AdvancedMatching to ensure at least three correspondences before running the tuple test, avoiding runtime errors and ineffective processing. Also updates the CHANGELOG to document this new behavior.

  • Add guard clause in AdvancedMatching for ncorr <= 2
  • Update CHANGELOG entry for this bug fix

Reviewed Changes

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

File Description
cpp/open3d/pipelines/registration/FastGlobalRegistration.cpp Added error handling and early return for insufficient correspondences in AdvancedMatching.
CHANGELOG.md Documented the new error handling for AdvancedMatching.
Comments suppressed due to low confidence (1)

cpp/open3d/pipelines/registration/FastGlobalRegistration.cpp:72

  • There are no unit tests covering this new guard for insufficient correspondences. Please add tests to verify behavior when ncorr < 3.
if (ncorr <= 2) {

int number_of_trial = ncorr * 100;

if (ncorr <= 2) {
utility::LogError(
Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

utility::LogError throws an exception by default, so the subsequent return {} is unreachable. Consider using a non-throwing logger (e.g., LogWarning) or removing the unreachable return.

Copilot uses AI. Check for mistakes.
- Add optional indices arg for fast computation of a small subset of FPFH features (PR #7118).

- Add error handling for insufficient correspondences in AdvancedMatching (PR #7234)

Copy link

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

There's an empty list item (- ) before the new changelog entry; remove it to maintain consistent formatting.

Suggested change

Copilot uses AI. Check for mistakes.
int number_of_trial = ncorr * 100;

if (ncorr <= 2) {
utility::LogError(
Copy link
Member

Choose a reason for hiding this comment

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

Hi @sutatoruta thanks for catching this! Can you update the Error to a Warning? LogError will throw an exception and disrupt calling code. Use it only when there is no valid result that we can return. Here {} is a valid result.

Copy link
Contributor Author

@sutatoruta sutatoruta May 24, 2025

Choose a reason for hiding this comment

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

@ssheorey Thank you for the review! You're absolutely right - I had mistakenly set the wrong error level.
This issue has been fixed in e195077.

@sutatoruta sutatoruta requested a review from ssheorey May 24, 2025 13:27
Copy link
Member

@ssheorey ssheorey left a comment

Choose a reason for hiding this comment

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

Thanks!

@ssheorey ssheorey merged commit 3f0db6a into isl-org:main May 27, 2025
33 of 39 checks passed
@sutatoruta sutatoruta deleted the fix/insufficient-correspondences-for-tuple-test branch May 27, 2025 15:48
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.

3 participants