-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Fix the ear clipping #2743
base: master
Are you sure you want to change the base?
Fix the ear clipping #2743
Conversation
All vertices in the gif above are on the plane, when move vertex 1 above the line of v2-v6, the triangle v2-v6-v1 will be regard as a ear. |
Ear clipping method get sometimes wrong result on some concave polygon. The original isEar() method only check whether there is any point in the triangle. It will get wrong result if the triangle don't have inside point but is a concave point of the polygon. Check the triangle each time in isEar() will fix this bug.
3d15436
to
fe5ec37
Compare
b081e75
to
264617b
Compare
Previous fixing will failed when input is in anti-clockwise. So add order check this time. The original area() method can't get right sign when input a anti-clockwise polygon. So change that with a try-catch like method. Here are the change log: 1. remove original area() and add new try-catch like order check method 2. For speed up the method, last three vertices will not do ear check 3. Update the unit test code for the updating
264617b
to
3d984b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smallchimney Thank you. Can you post the same gif animation, with your fix implemented?
float | ||
area (const std::vector<uint32_t>& vertices); | ||
size_t | ||
triangulate (std::vector<uint32_t>& vertices, PolygonMesh& output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taketwo what's our policy on API changes of non-virtual protected methods? Purist side: still breaks the API since our consumers might have derived classes from this and use this method. Pragmatic side: unlikely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think generallry we can approach "protected" API stability in a relaxed way, i.e. accept breakage without deprecation cycle. That said, isn't it super easy to keep area()
method around and thus definitely not break anyone's code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't checked yet. I decided to read a little on ear clipping triangulation before having a look with some proper eyes to the PR. I was failing to get the jargon of the OP. ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is not used at all, so there's no reason to keep it around. I would remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK! After a more careful review I've reached an opinion on what to preserve and what not to preserve :)
- From your first commit I'm ok in keeping it all, plus the small fix you added on the second commit.
- From the second commit I'm only interested in the removal of the
area
method and the changes to the unit test.
I'm explicitly keeping out the triangulate
refactoring and all those changes from push_back
to emplace_back
in the cases where an actual copy is taking place.
Ideally, your fix and the changes to unit test should all in the first commit, the removal of the area method, on a separate commit.
float | ||
area (const std::vector<uint32_t>& vertices); | ||
size_t | ||
triangulate (std::vector<uint32_t>& vertices, PolygonMesh& output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is not used at all, so there's no reason to keep it around. I would remove it.
|
This pull request has been automatically marked as stale because it hasn't had Come back whenever you have time. We look forward to your contribution. |
It seems the code has been merged in jsk-ros-pkg/jsk_recognition#2447, so I will close this PR. |
I made a mistake, the changes was not merged into PCL |
Ear clipping method get sometimes wrong result on some concave polygon.
The original isEar() method only check whether there is any point in the triangle. It will get wrong result if the triangle don't have inside point but is a concave point of the polygon. Check the triangle each time in isEar() will fix this bug.