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

Implement open3d::t::geometry::TriangleMesh::SelectByIndex #6415

Merged
merged 3 commits into from
Nov 13, 2023

Commits on Nov 7, 2023

  1. 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;
        // ...
    });
    nsaiapova committed Nov 7, 2023
    Configuration menu
    Copy the full SHA
    7463b10 View commit details
    Browse the repository at this point in the history

Commits on Nov 8, 2023

  1. 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.
    nsaiapova committed Nov 8, 2023
    Configuration menu
    Copy the full SHA
    0a78111 View commit details
    Browse the repository at this point in the history
  2. 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
    nsaiapova committed Nov 8, 2023
    Configuration menu
    Copy the full SHA
    defc9df View commit details
    Browse the repository at this point in the history