# Path: trimesh/grouping.py
# def unique_rows(data, digits=None):
#     '''
#     Returns indices of unique rows. It will return the
#     first occurrence of a row that is duplicated:
#     [[1,2], [3,4], [1,2]] will return [0,1]
# 
#     Arguments
#     ---------
#     data: (n,m) set of floating point data
#     digits: how many digits to consider for the purposes of uniqueness
# 
#     Returns
#     --------
#     unique:  (j) array, index in data which is a unique row
#     inverse: (n) length array to reconstruct original
#                  example: unique[inverse] == data
#     '''
#     hashes = hashable_rows(data, digits=digits)
#     garbage, unique, inverse = np.unique(hashes,
#                                          return_index=True,
#                                          return_inverse=True)
#     return unique, inverse


import numpy as np
from .grouping import unique_rows
    Arguments
    ----------
    mesh: Trimesh object
    face_index: faces to subdivide.
                if None: all faces of mesh will be subdivided
                if (n,) int array of indices: only specified faces will be
                   subdivided. Note that in this case the mesh will generally
                   no longer be manifold, as the additional vertex on the midpoint
                   will not be used by the adjacent faces to the faces specified,
                   and an additional postprocessing step will be required to
                   make resulting mesh watertight


    '''
    if face_index is None:
        face_index = np.arange(len(mesh.faces))
    else:
        face_index = np.asanyarray(face_index, dtype=np.int64)

    # the (c,3) int set of vertex indices
    faces = mesh.faces[face_index]
    # the (c, 3, 3) float set of points in the triangles
    triangles = mesh.triangles[face_index]
    # the 3 midpoints of each triangle edge vstacked to a (3*c, 3) float
    mid = np.vstack([triangles[:, g, :].mean(axis=1) for g in [[0, 1],
                                                               [1, 2],
                                                               [2, 0]]])
    mid_idx = (np.arange(len(face_index) * 3)).reshape((3, -1)).T
    # for adjacent faces we are going to be generating the same midpoint
    # twice, so we handle it here by finding the unique vertices

# Path: trimesh/grouping.py
# def unique_rows(data, digits=None):
#     '''
#     Returns indices of unique rows. It will return the
#     first occurrence of a row that is duplicated:
#     [[1,2], [3,4], [1,2]] will return [0,1]
# 
#     Arguments
#     ---------
#     data: (n,m) set of floating point data
#     digits: how many digits to consider for the purposes of uniqueness
# 
#     Returns
#     --------
#     unique:  (j) array, index in data which is a unique row
#     inverse: (n) length array to reconstruct original
#                  example: unique[inverse] == data
#     '''
#     hashes = hashable_rows(data, digits=digits)
#     garbage, unique, inverse = np.unique(hashes,
#                                          return_index=True,
#                                          return_inverse=True)
#     return unique, inverse


# Path: trimesh/remesh.py
import numpy as np
from .grouping import unique_rows

    Arguments
    ----------
    mesh: Trimesh object
    face_index: faces to subdivide.
                if None: all faces of mesh will be subdivided
                if (n,) int array of indices: only specified faces will be
                   subdivided. Note that in this case the mesh will generally
                   no longer be manifold, as the additional vertex on the midpoint
                   will not be used by the adjacent faces to the faces specified,
                   and an additional postprocessing step will be required to
                   make resulting mesh watertight


    '''
    if face_index is None:
        face_index = np.arange(len(mesh.faces))
    else:
        face_index = np.asanyarray(face_index, dtype=np.int64)

    # the (c,3) int set of vertex indices
    faces = mesh.faces[face_index]
    # the (c, 3, 3) float set of points in the triangles
    triangles = mesh.triangles[face_index]
    # the 3 midpoints of each triangle edge vstacked to a (3*c, 3) float
    mid = np.vstack([triangles[:, g, :].mean(axis=1) for g in [[0, 1],
                                                               [1, 2],
                                                               [2, 0]]])
    mid_idx = (np.arange(len(face_index) * 3)).reshape((3, -1)).T
    # for adjacent faces we are going to be generating the same midpoint
    # twice, so we handle it here by finding the unique vertices

    unique, inverse = unique_rows(mid)