Simplify data_ and data_interface_ in KDTreeFlann. #6734
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type
Motivation and Context
KDTreeFlann::SetRawData
had some confusion arounddata
,data_
, anddata_interface_
.As a result, the data from the parameter was copied to the member
std::vector
, but the interface (which uses anEigen::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:
python util/check_style.py --apply
to apply Open3D code styleto my code.
updated accordingly.
results (e.g. screenshots or numbers) here.
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 thanprivate
, but the build didn't break.I will update the fix if subclasses are borken.