Skip to content

Reduce time taken in CropHull by using O(n) pre-filtering with CropBox #3883

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

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

DaniilSNikulin
Copy link
Contributor

@DaniilSNikulin DaniilSNikulin commented Apr 7, 2020

Firstly reason for PR was only issue #3875: add CropBox inside CropHull for increasing performance.

In progress was founded and fixed some bugs:

  1. issue CropHull 3d not cropping inside #1657. Solving for this bug was founded in comments in CropHull 3d not cropping inside #1657.
  2. function applyFilter didn't clear output data before start adding new
    point or indices.

Added unit tests for CropHull. (only ConvexHull case).

Also was deleted some duplicated code. Implementation for cloud and indices filtering was equals, but duplicates.

resolve #1657
resolve #3541
resolve #3960

UPD:

  • delete CropHull::applyFilter[23]D(PointCloud) -- private and not used
  • delete CropHull::applyFilter(PointCloud) -- FilterIndices::applyFilter(PointCloud) already have got implementation
  • deleted CropHull::applyFilter fix bug: FilterIndices funtionality for keepOrganized cloud was missed in original implementation
  • set extract_removed_indices default to true and support removed_indices functionality, which was missed (issue Removed Indiices in crop_hull #3541 )
  • add tests for CropHull: check Filter and FilterIndices functionality.
  • perfomance testing: PCL.ConvexHull_2dsquare w/o CrobBox spent 131ms, w/ spent 51ms; PCL.ConvexHull_3dcube w/o CropBox spent 1971ms, w/ spent 1317ms
  • changed API: add flag extract_removed_indices to CropHull constructor [default=false]

Daniil Nikulin added 4 commits April 7, 2020 18:37
@kunaltyagi kunaltyagi self-requested a review April 7, 2020 22:23
@kunaltyagi kunaltyagi self-requested a review April 7, 2020 22:23
DaniilSNikulin and others added 2 commits April 8, 2020 20:08
suggestions `resize(0)` -> `clear` from @kunaltyagi

Co-Authored-By: Kunal Tyagi <tyagi.kunal@live.com>
@kunaltyagi kunaltyagi added changelog: enhancement Meta-information for changelog generation module: filters needs: more work Specify why not closed/merged yet changelog: ABI break Meta-information for changelog generation labels Apr 8, 2020
@kunaltyagi kunaltyagi changed the title Issue #3875 using crop box inside crop hull Reduce time taken in CropHull by using O(n) pre-filtering with CropBox Apr 8, 2020
Daniil Nikulin added 2 commits April 9, 2020 19:59
* delete unused coments of code (2 lines)

* delete applyFilter[23]D(PointCloud) -- private and not used

* delete applyFilter(PointCloud) -- FilterIndices already have got
* implementation

* deleted applyFilter fix bug: FilterIndices funtionality for
* keepOrganized cloud was missed in original implementation

* set extract_removed_indices default to true and support
* removed_indices functionality

* perfomance testing: PCL.ConvexHull_2dsquare w/o CrobBox spent 76ms,
* w/ spent 28ms; PCL.ConvexHull_3dcube w/o CropBox spent 1034ms, w/
* spent 640ms
@kunaltyagi kunaltyagi self-requested a review April 10, 2020 01:39
@SergioRAgostinho
Copy link
Member

SergioRAgostinho commented Apr 11, 2020

Just a reminder to remember to try to keep these PRs as atomic as possible. Avoid the urge to fix the internals of the class unless the PR is all about that. As an example: I would split this PR with its original intent, 1 PR for fixing the original bug, another to change CropHull to prefilter with CropBox.

Just keep those things in mind before venturing into optimizing the internals.

Daniil Nikulin and others added 5 commits April 12, 2020 14:19
@SergioRAgostinho SergioRAgostinho added needs: code review Specify why not closed/merged yet and removed needs: more work Specify why not closed/merged yet labels Apr 14, 2020
1. int -> pcl::index_t
2. std::vector<int> -> pcl::Indices
3. for loop ASSERT_EQ -> pcl::tests::EXPECT_EQ_VECTORS
Copy link
Member

@kunaltyagi kunaltyagi left a comment

Choose a reason for hiding this comment

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

The tests can be rewritten to be more maintainable.


cropHullFilter.setHullIndices(hullPolygons);
cropHullFilter.setHullCloud(hullPoints);
//cropHullFilter.setDim(2); // if you uncomment this, it will work
Copy link
Member

Choose a reason for hiding this comment

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

What is this comment for?

pcl::Indices filteredIndices;
cropHullFilter.filter(filteredIndices);
pcl::test::EXPECT_EQ_VECTORS(testData.insideIndices, filteredIndices);
cropHullFilter.filter(filteredIndices);
Copy link
Member

Choose a reason for hiding this comment

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

Seems to be duplicated check wrt 2 lines before

Copy link
Contributor Author

@DaniilSNikulin DaniilSNikulin Apr 24, 2020

Choose a reason for hiding this comment

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

this test check reentrancy of function filter. results should not depend on amount of calls before.
PS: maybe I'm not correct use termin of reentrancy and it must rename to repeatability

Copy link
Member

Choose a reason for hiding this comment

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

Pure function?

pcl::Indices filteredIndices;
cropHullFilter.filter(filteredIndices);
pcl::test::EXPECT_EQ_VECTORS(testData.insideIndices, filteredIndices);
cropHullFilter.filter(filteredIndices);
Copy link
Member

Choose a reason for hiding this comment

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

Pure function?

for (std::size_t index = 0; index < indices_->size (); index++)
const bool keepInside = crop_outside_ ^ negative_;

pcl::Indices cropInlierIndices;
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a note here why we're doing this since this is the core contribution of the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: ABI break Meta-information for changelog generation changelog: enhancement Meta-information for changelog generation module: filters needs: pr merge Specify why not closed/merged yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removed Indiices in crop_hull CropHull 3d not cropping inside [filters] Why CropHull getHullCloudRange doesn't use hull_cloud_
4 participants