-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement open3d::t::geometry::TriangleMesh::SelectByIndex (#6415)
* Define a helper DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE This is a helper to call a templated function with an integer argument, based on Dtype. As a second argument, it takes a suffix, used to build a unique type name. This way, we can use it to call a function with more than one integer argument. Example: DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE(core::Dtype::Int32, int32, [&]() { DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE(core::Dtype::UInt64, uint64, [&]() { scalar_int32_t a; scalar_uint64_t b; // ... }); * Implement open3d::t::geometry::TriangleMesh::SelectByIndex The method takes a list of indices and returns a new mesh built with the selected vertices and triangles formed by these vertices. The indices type can be any integral type. The algorithm is implemented on CPU only. The implementation is inspired by open3d::geometry::TriangleMesh::SelectByIndex. and by open3d::t::geometry::TriangleMesh::SelectFacesByMask. We first compute a mask of vertices to be selected. If the input index exceeds the maximum number of vertices or is negative, we ignore the index and print a warning. If the mesh has triangles, we build tringle mask and select needed triangles. The next step is to update triangle indices to a new ones. It is similar to SelectFacesByMask, so I introduced a static helper to do that. Based on the vertex mask we build a mapping index vector using inclusive prefix sum algorithm and use it as a map between old and new indices. We select the vertices by mask and build the resulting mesh from the selected vertices and triangles. Copying the mesh attributes is again similar to SelectFacesByMask, so I put it to a separate static function. * Refactor t::geometry::TriangleMesh::SelectFacesByMask * Add error handling on empty mesh * Use DISPATCH_INT_DTYPE_PREFIX_TO_TEMPLATE instead of a conditional branch * Use UpdateTriangleIndicesByVertexMask helper to update triangle indices * Use CopyAttributesByMask helper to copy the mesh attributes * Add tests
- Loading branch information
Showing
6 changed files
with
739 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.