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

Pad using weighted vertex normals #238

Merged
merged 6 commits into from
May 6, 2024

Conversation

kbrameld
Copy link
Contributor

@kbrameld kbrameld commented Apr 2, 2024

Resolves: #76

As discussed in the linked issue, padding behavior for complex meshes are not good. These changes improve upon the padding functionality, and obtain a closer functionality to blender's fatten method. Two main changes:

  • padding is performed in direction of vertex normal instead of direction from center of mesh
  • calculates better weighted vertex normal by accounting for the angle of a face at a vertex.
A complex STL file (original) Current padding method
Screenshot from 2024-04-02 15-01-38 Screenshot from 2024-04-02 14-01-02
Fatten method (in Blender) New padding method
Screenshot from 2024-04-02 11-39-09 Screenshot from 2024-04-02 14-27-05
Non-uniform padding x-direction y-direction z-direction
Screenshot from 2024-04-02 15-00-00 Screenshot from 2024-04-02 15-32-50 Screenshot from 2024-04-02 15-32-27

As discussed in the linked issue, although this is a general improvement, this change may potentially affect behavior in downstream packages if they relied on the bad padding.

@peci1
Copy link
Contributor

peci1 commented Apr 2, 2024

Wow, it's been a long time since I was interested in this issue.

In #127, I found:

Another comment was that generally change of the current behavior is okay as long as we can provide some guarantees on the relationship between the old approach and the new one (i.e. all points contained by the old behavior would be contained by the new one, or so...).

Could you sketch up a "proof" of some relationship?

Or, alternatively, wouldn't it be easier to create a function with a new name (fatten?) instead of scaleAndPad to retain the original behavior for existing code?

@kbrameld
Copy link
Contributor Author

kbrameld commented Apr 2, 2024

Another comment was that generally change of the current behavior is okay as long as we can provide some guarantees on the relationship between the old approach and the new one (i.e. all points contained by the old behavior would be contained by the new one, or so...).

Not sure if there is a nice relationship. The old padding method was closer to a scaling operation, and the resulting mesh often didn't include the original vertices. Here's an example with the blue being the padded shapes:

Old method New Method
Screenshot from 2024-03-14 14-54-19 Screenshot from 2024-03-14 14-46-05

The only meshes that will look similar between the old and new method will be meshes where the weighted vertex normal direction is close to the direction of the vertex from the center. (eg. cube, sphere meshes) For any other mesh, the padded shapes will look different.

Or, alternatively, wouldn't it be easier to create a function with a new name (fatten?) instead of scaleAndPad to retain the original behavior for existing code?

Yes, this can be considered an alternative. If we go this approach, I advocate for deprecating the "pad" methods (in upcoming ros2 distros).

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution.
Given that the old mesh padding was not working as expected, I don't see the need to introduce the new behavior with a new name. I even suggest replacing the old method computeVertexNormals() with the new one.

src/shapes.cpp Outdated Show resolved Hide resolved
src/shapes.cpp Outdated Show resolved Hide resolved
src/shapes.cpp Outdated Show resolved Hide resolved
src/shapes.cpp Outdated Show resolved Hide resolved
@peci1
Copy link
Contributor

peci1 commented Apr 3, 2024

Given that the old mesh padding was not working as expected, I don't see the need to introduce the new behavior with a new name.

At least robot_body_filter users actively use padding with its current behavior. Any big changes could break their workflows. But as long as the result is similar for the commonly found meshes (e.g. UR-5), it should be okay. I think the example mesh used in this PR is kind of extreme and very far from what people normally use, so the big difference in the example is okay.

@peci1
Copy link
Contributor

peci1 commented Apr 3, 2024

@kbrameld Do I get it correctly that the unexpected case of enlarging a square would still be present with this PR? #127 (comment) .

@kbrameld
Copy link
Contributor Author

kbrameld commented Apr 3, 2024

@kbrameld Do I get it correctly that the unexpected case of enlarging a square would still be present with this PR? #127 (comment) .

You're correct, the changes in this PR won't change the behavior of enlarging the square in that issue.

src/shapes.cpp Outdated Show resolved Hide resolved
@ijnek
Copy link

ijnek commented Apr 12, 2024

Once this is merged, I will create a PR against the ros2 branch too. What's required to move forward with this PR?

@ijnek
Copy link

ijnek commented May 6, 2024

Pinging this thread for attention to be reviewed

@rhaschke
Copy link
Contributor

rhaschke commented May 6, 2024

Merging this, w/o a second review as nobody seems to do it...

@rhaschke rhaschke merged commit dc86108 into moveit:noetic-devel May 6, 2024
4 checks passed
@kbrameld kbrameld deleted the feat/weighted-vertex-normals branch May 6, 2024 17:56
@kbrameld
Copy link
Contributor Author

kbrameld commented May 6, 2024

Thanks for reviewing @rhaschke!

@peci1
Copy link
Contributor

peci1 commented May 7, 2024

I've tested robot_body_filter (which uses geometric_shapes) with a few models from https://github.com/ctu-vras/rosdevday_cloud_filtering and the models seem to be affected only a little by this PR. So it seems this change should be safe for most users! Thanks.

@timonegk
Copy link

timonegk commented May 27, 2024

Once this is merged, I will create a PR against the ros2 branch too.

Now that this is merged, could you create a PR for ROS 2?

kbrameld added a commit to traclabs/geometric_shapes that referenced this pull request May 29, 2024
rhaschke pushed a commit that referenced this pull request Jul 18, 2024
* Improve padding of meshes using weighted vertex normals (#238)
* Use eigen to compute angle between vertex normals to avoid nans

---------

Co-authored-by: Mike Lanighan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-uniform padding of non-convex, long meshes
5 participants