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

Simplify data_ and data_interface_ in KDTreeFlann. #6734

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

PieroV
Copy link
Contributor

@PieroV PieroV commented Mar 29, 2024

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes KDTreeFlann search error with step by step run #6235 (there might be others related)
  • 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

KDTreeFlann::SetRawData had some confusion around data, data_, and data_interface_.

As a result, the data from the parameter was copied to the member std::vector, but the interface (which uses an Eigen::Map) used the data passed as an argument to the method.
As a result, the searches risked to be run on a dangling pointer, instead of the intended internal storage.

This produced unexpected/wrong results sometimes.

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 have not updated any documentation, because I'm fixing a bug
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

The most surgical change would make change the existing Eigen::Map to refer the internal storage.

However, I noticed that the 4 members (data_, data_interface_, dimension_, dataset_size_) were all to be kept in sync.
So, I preferred simplifying the code, copy the argument to an Eigen::MatrixXd and remove everything else (I replaced the dataset size and dimension with the rows and cols of the new matrix, and the matrix itself is the owner of the storage).

I noticed the data was protected, rather than private, but the build didn't break.
I will update the fix if subclasses are borken.

Copy link

update-docs bot commented Mar 29, 2024

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@PieroV
Copy link
Contributor Author

PieroV commented Mar 29, 2024

I have some problems in getting clang-format-10, so I didn't

Seriously though, the CI could at least give a patch to apply to make the formatting pass 😅.

KDTreeFlann::SetRawData had some confusion around data, data_, and
data_interface_. As a result, the data from the parameter was copied to
the member std::vector, but the interface (which takes an Eigen::Map)
used the data passed as an argument to the method.
As a result, the searches risked to be run on a dangling pointer,
instead of the intended internal storage.

However, rather than adjusting the pointer for Eigen::Map, I preferred
simplifying the code, and copy the argument to an Eigen::MatrixXd.
@ssheorey
Copy link
Member

ssheorey commented Mar 31, 2024

I have some problems in getting clang-format-10, so I didn't

Seriously though, the CI could at least give a patch to apply to make the formatting pass 😅.

Sorry about that - the CI script can actually fix the formatting for you:

cd build; make apply-style or
python util/check_style.py --apply

A great quality of life improvement would be to make an automatic bot commit this in the CI.

clang-format-10 should be (perpetually?) available through pip install clang-format~=10.0

@PieroV
Copy link
Contributor Author

PieroV commented Apr 1, 2024

No worries, eventually I managed to format 😄.

clang-format-10 should be (perpetually?) available through pip install clang-format~=10.0

Thanks, I didn't know this!
I ran clang-format-10 in an Ubuntu live VM creted on the fly instead 😂. Installing with pip should be definitely easier 🙂.

@ssheorey ssheorey self-requested a review April 17, 2024 23:02
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 @PieroV . Looks good!

@ssheorey ssheorey merged commit 785878f into isl-org:main Apr 17, 2024
32 of 33 checks passed
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.

KDTreeFlann search error with step by step run
2 participants