-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[Mesh] TriangleMesh's "+=" operator appends UVs regardless of the presence of existing features #6728
Conversation
…e of existing features.
Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes. |
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.
@cdbharath Thanks for your PR, please have a look at the comment
@@ -77,30 +74,29 @@ TriangleMesh &TriangleMesh::operator+=(const TriangleMesh &mesh) { | |||
if (HasAdjacencyList()) { | |||
ComputeAdjacencyList(); | |||
} | |||
if (add_textures) { | |||
if (mesh.HasTriangleUvs()) { | |||
size_t old_tri_uv_num = triangle_uvs_.size(); | |||
triangle_uvs_.resize(old_tri_uv_num + mesh.triangle_uvs_.size()); |
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.
If this
does not have any UV coordinates then triangle_uvs_.size()
will be different from the total number of triangles in the resulting mesh. This would break with the assumption that triangle_uvs_.size() == 3*number of triangles
Hi @cdbharath , we think mixing meshes with and without texture uvs can be problematic. I added a special case for empty meshes that allows your workflow with the += operator. |
} else { | ||
triangle_uvs_.clear(); | ||
textures_.clear(); | ||
triangle_material_ids_.clear(); | ||
} |
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.
We need to keep this portion - clear()
properties if only one mesh has them (unless the other mesh is empty), else we will get meshes with only half the triangles with material ids, etc. (e.g. if this
has material_ids, but mesh
doesn't, output should not have material ids.) Half populated properties will cause seg faults.
Also, textures and triangle_material_ids go together, so we should have a single if()
for them. We want n_textures == max(triangle_material_ids_)+1
and either both or none should be present always.
@cdbharath this PR may break other mesh functions if there is a bug -- please do the following tests and make sure there are no errors. Check for the case where:
- a has texture_uvs but no textures / triangle_material_ids
- b has all of texture_uvs, textures and triangle_material_ids
- c has none of the 3 (but has triangles)
With these 3 meshes, perform this check:
a+=b
andb+=a
should produce the same results in a and b respectively (test mesh equality). Also for the paira+=c
,c+=a
, and separately for the pairb+=c
andc+=b
. [Add this to C++ unit tests if not present already] Visualize the resulting mesh correctly with draw_geometries() and draw() [Just test visualization on your computer - no unit tests required]
@benjaminum @ssheorey I have addressed the posted issues. I also added an unit test for |
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.
lgtm
Allows appending of UV coordinates, textures and material IDs with
+=
operator overload inTriangleMesh
class irrespective of the presence of these attributes in the existing mesh (mesh on LHS to += operator)Type
Motivation and Context
The
+=
operator overload ofTriangleMesh
class does not append UV coordinates, textures and material IDs when the existing mesh (mesh on LHS to += operator) already contains any of these attributes. There is no reason to limit+=
for UVs toTriangleMesh
with the attributes already assigned as it currently happens here.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 current change doesn't check if the presence of UV coordinates, textures and material IDs in the existing mesh and appends only based on their availability in the incoming mesh.
I am attaching a screenshot that shows the addition of UV coordinates based on
+=
operator. The test code is as followsCase 1: Both box and sphere has UVs, textures and material IDs
Note: First 2 images are inputs and the 3rd image is the output
Case 2: Box has UVs, textures and material IDs. But sphere has only UVs
Note: First 2 images are inputs and the 3rd image is the output
Case 3: Sphere has UVs, textures and material IDs. But box has only textures and material IDs
Note: First 2 images are inputs and the 3rd image is the output