Exemplo n.º 1
0
def volume_curvature_normal_smooth(triangles, vertices, nb_iter=1,
                                   diffusion_step=1.0, area_weighted=False,
                                   backward_step=False, flow_file=None):
    if isinstance(diffusion_step, (int, float)):
        diffusion_step = diffusion_step * np.ones(len(vertices))

    if flow_file is not None:
        mem_map = np.memmap(flow_file, dtype=G_DTYPE, mode='w+',
                            shape=(nb_iter, vertices.shape[0], vertices.shape[1]))

    for i in range(nb_iter):
        stdout.write("\r step %d on %d done" % (i, nb_iter))
        stdout.flush()
        if flow_file is not None:
            mem_map[i] = vertices
        # get curvature_normal_matrix
        # todo not optimal, because operation done twice etc
        curvature_normal_mtx = mean_curvature_normal_matrix(
            triangles, vertices, area_weighted=area_weighted)
        # do the first step
        next_vertices = euler_step(curvature_normal_mtx, csc_matrix(
            vertices), diffusion_step, backward_step).toarray()
        # test if direction is positive
        direction = next_vertices - vertices
        normal_dir = vertices_cotan_normal(triangles, vertices, normalize=True)
        dotv = dot(normalize_vectors(direction), normal_dir, keepdims=True)
        vertices += direction * np.maximum(0.0, -dotv)

    stdout.write("\r step %d on %d done \n" % (nb_iter, nb_iter))
    return vertices
Exemplo n.º 2
0
def vertices_normal(triangles, vertices, normalize=True, area_weighted=True):
    tri_normal = triangles_normal(triangles, vertices, normalize=area_weighted)
    tv_matrix = triangle_vertex_map(triangles, vertices)
    vts_normal = tv_matrix.T.dot(tri_normal)

    if normalize:
        return normalize_vectors(vts_normal)
    return vts_normal
Exemplo n.º 3
0
def triangles_normal(triangles, vertices, normalize=True):
    if scipy.sparse.__name__ in type(vertices).__module__:
        vertices = vertices.toarray()
    e1 = vertices[triangles[:, 1]] - vertices[triangles[:, 0]]
    e2 = vertices[triangles[:, 2]] - vertices[triangles[:, 0]]
    normal = np.cross(e1, e2)

    if normalize:
        return normalize_vectors(normal)
    return normal
Exemplo n.º 4
0
def vertices_cotan_direction(triangles,
                             vertices,
                             normalize=True,
                             area_weighted=True):
    from trimeshpy.math.matrix import mean_curvature_normal_matrix
    curvature_normal_mtx = mean_curvature_normal_matrix(
        triangles, vertices, area_weighted=area_weighted)
    cotan_normal = curvature_normal_mtx.dot(vertices)

    if normalize:
        return normalize_vectors(cotan_normal)
    return cotan_normal
Exemplo n.º 5
0
def volume_mass_stiffness_smooth(triangles,
                                 vertices,
                                 nb_iter=1,
                                 diffusion_step=1.0,
                                 flow_file=None):
    vertices_csc = csc_matrix(vertices)
    curvature_normal_mtx = mean_curvature_normal_matrix(triangles,
                                                        vertices,
                                                        area_weighted=False)

    if isinstance(diffusion_step, (int, long, float)):
        diffusion_step = diffusion_step * np.ones(len(vertices))

    if flow_file is not None:
        mem_map = np.memmap(flow_file,
                            dtype=G_DTYPE,
                            mode='w+',
                            shape=(nb_iter, vertices.shape[0],
                                   vertices.shape[1]))

    for i in range(nb_iter):
        stdout.write("\r step %d on %d done" % (i, nb_iter))
        stdout.flush()
        if flow_file is not None:
            mem_map[i] = vertices_csc.toarray()
        # get curvature_normal_matrix
        mass_mtx = mass_matrix(triangles, vertices)

        raise NotImplementedError()
        # (D - d*L)*y = D*x = b
        A_matrix = mass_mtx - \
            diags(diffusion_step, 0).dot(curvature_normal_mtx)
        b_matrix = mass_mtx.dot(csc_matrix(vertices_csc))
        next_vertices = spsolve(A_matrix, b_matrix)
        # test if direction is positive
        direction = next_vertices.toarray() - vertices_csc
        normal_dir = vertices_cotan_normal(triangles,
                                           next_vertices,
                                           normalize=True)
        dotv = normalize_vectors(direction).multiply(normal_dir)
        vertices_csc += direction * np.maximum(0.0, -dotv)
        # vertices_csc += direction * sigmoid(-np.arctan(dotv)*np.pi - np.pi)
        # vertices_csc += direction * softplus(-dotv)

    stdout.write("\r step %d on %d done \n" % (nb_iter, nb_iter))
    return vertices_csc.toarray()
Exemplo n.º 6
0
def vertices_cotan_normal(triangles,
                          vertices,
                          normalize=True,
                          area_weighted=True):
    from trimeshpy.math.curvature import vertices_cotan_direction
    if scipy.sparse.__name__ in type(vertices).__module__:
        vertices = vertices.toarray()

    cotan_normal = vertices_cotan_direction(triangles,
                                            vertices,
                                            normalize=False,
                                            area_weighted=area_weighted)
    vts_normal = vertices_normal(triangles,
                                 vertices,
                                 normalize=False,
                                 area_weighted=area_weighted)

    # inverse inverted cotan_normal direction
    cotan_normal = np.sign(dot(cotan_normal, vts_normal,
                               keepdims=True)) * cotan_normal

    if normalize:
        return normalize_vectors(cotan_normal)
    return cotan_normal