Ejemplo n.º 1
0
import slam.io as sio
import slam.plot as splt
import slam.vertex_voronoi as svv
import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib
# matplotlib.use('TkAgg')

if __name__ == '__main__':

    mesh = sio.load_mesh('data/example_mesh.gii')
    mesh.apply_transform(mesh.principal_inertia_transform)

    vert_vor = svv.vertex_voronoi(mesh)
    print(mesh.vertices.shape)
    print(vert_vor.shape)
    print(np.sum(vert_vor) - mesh.area)

    splt.pyglet_plot(mesh, vert_vor, plot_colormap=True)
Ejemplo n.º 2
0
import slam.plot as splt
import slam.io as sio
import slam.geodesics as sgeo
import numpy as np
import trimesh

if __name__ == '__main__':

    mesh = sio.load_mesh('data/example_mesh.gii')

    vert_id = 0
    max_geodist = 10

    geo_distance = sgeo.compute_gdist(mesh, vert_id)
    splt.pyglet_plot(mesh, geo_distance, plot_colormap=True)
    # get the vertices index in specified geo_distance of vert
    area_geodist_vi = np.where(geo_distance < max_geodist)[0]
    print(area_geodist_vi)

    area_geodist = sgeo.local_gdist_matrix(mesh, max_geodist)
    splt.pyglet_plot(mesh, area_geodist[0].toarray().squeeze(),
                     plot_colormap=True)
    # print(area_geodist[0].toarray()-geo_distance)

    # print the vertex index
    for i in range(mesh.vertices.shape[0]):
        vert_distmap = area_geodist[i].toarray()[0]
        area_geodist_v = np.where(vert_distmap > 0)[0]
        print(area_geodist_v)
    #
Ejemplo n.º 3
0
import trimesh
import slam.plot as splt
import slam.io as sio

if __name__ == '__main__':
    mesh_file = 'data/example_mesh.gii'
    texture_file = 'data/example_texture.gii'

    mesh = sio.load_mesh(mesh_file)
    mesh.apply_transform(mesh.principal_inertia_transform)
    tex = sio.load_texture(texture_file)

    splt.pyglet_plot(mesh, tex.darray, plot_colormap=True)
    splt.pyglet_plot(mesh, tex.darray, 'hot', plot_colormap=True)
    """ set each facet to a random color
    colors are 8 bit RGBA by default (n,4) np.uint8
    for facet in mesh.facets:
        mesh.visual.face_colors[facet] = trimesh.visual.random_color()
    """
    for vert_ind in range(len(mesh.visual.vertex_colors)):
        mesh.visual.vertex_colors[vert_ind] = trimesh.visual.random_color()

    # preview mesh in an opengl window if you installed pyglet with pip
    mesh.show()
Ejemplo n.º 4
0
        sphere_transformed_mesh = sphmap.inverse_stereo_projection(
            plan_complex_transfo, invert=False)
        all_spheres.append(sphere_transformed_mesh)
        angle_diff = sdst.angle_difference(sphere_mesh,
                                           sphere_transformed_mesh)
        all_angle_diff.append(angle_diff)
        area_diff = sdst.area_difference(sphere_mesh, sphere_transformed_mesh)
        all_area_diff.append(area_diff)
        poly_angles = meshPolygonAngles(sphere_transformed_mesh.vertices,
                                        sphere_transformed_mesh.faces)
        print(np.max(sphere_transformed_mesh.face_angles - poly_angles))
        poly_areas = meshPolygonArea(sphere_transformed_mesh.vertices,
                                     sphere_transformed_mesh.faces)
        print(np.max(sphere_transformed_mesh.area_faces - poly_areas))
    splt.pyglet_plot(sphere_transformed_mesh,
                     z_coord_texture,
                     caption="moebius transformed sphere")

    int_area = [np.sum(np.abs(v)) for v in all_area_diff]
    int_angle = [np.sum(np.abs(angle_diff).flatten()) for v in all_angle_diff]
    fig, ax = plt.subplots(1, 1)
    ax.set_xlabel('moebius scaling parameter')
    funct1 = ax.plot(all_steps, int_area, 'o-', label='area')
    ax.set_ylabel('integral of area distortionss')

    # Share the x-axis for both the axes (ax1, ax2)
    ax2 = ax.twinx()
    funct2 = ax2.plot(all_steps, int_angle, 'rs-', label='angle')
    ax2.set_ylabel('integral of angle distortions')
    ax2.set_ylim([-0.1, 3.14])
Ejemplo n.º 5
0
    # ax[1].grid(True)
    # ax[2].set_title('edges')
    # ax[2].hist(edge_diff.flatten())
    # ax[2].grid(True)
    plt.show()

    sphere_mesh = sps.generate_sphere(1000)
    print(np.mean(sphere_mesh.vertices))
    print(np.sqrt(np.sum(np.power(sphere_mesh.vertices, 2), 1)))
    z_coord_texture = sphere_mesh.vertices[:, 2]

    poly_angles = meshPolygonAngles(sphere_mesh.vertices, sphere_mesh.faces)
    print(np.max(poly_angles))
    print(np.min(poly_angles))

    splt.pyglet_plot(sphere_mesh, z_coord_texture, caption="Sphere")
    #
    # # plane_proj_mesh = sphmap.stereo_projection(sphere_mesh, invert=False)
    # # splt.pyglet_plot(plane_proj_mesh,
    # # z_coord_texture, caption="projected onto a plane")
    #
    # # plane_proj_mesh = sphmap.stereo_projection(sphere_mesh)
    # # splt.pyglet_plot(plane_proj_mesh, z_coord_texture,
    # #                  caption="projected onto a plane")
    # #
    # # inv_plane_proj_mesh = sphmap.inverse_stereo_projection(plane_proj_mesh)
    # # splt.pyglet_plot(inv_plane_proj_mesh, z_coord_texture,
    # #                  caption="inverse projected onto a plane")
    #
    # b = complex(0., 0.)
    # c = complex(0., 0.)
Ejemplo n.º 6
0
import trimesh
import slam.plot as splt
import slam.io as sio
import matplotlib.pyplot as plt

if __name__ == '__main__':

    mesh_file = 'data/example_mesh.gii'
    texture_file = 'data/example_texture.gii'

    mesh = sio.load_mesh(mesh_file)
    mesh.apply_transform(mesh.principal_inertia_transform)
    tex = sio.load_texture(texture_file)
    # most simple mesh visualization
    splt.pyglet_plot(mesh)
    # with a texture
    splt.pyglet_plot(mesh, tex.darray[0], plot_colormap=True)
    # change in colormap
    splt.pyglet_plot(mesh,
                     tex.darray[0],
                     color_map=plt.get_cmap('hot', 6),
                     plot_colormap=True)
    # to save to disc as png, we need to get the output of the plot function
    plot_output = splt.pyglet_plot(mesh,
                                   tex.darray[0],
                                   color_map=plt.get_cmap('hot'),
                                   plot_colormap=True)
    # then save the 3D rendering figure
    # splt.save_image(plot_output[0], png_fig_filename)
    # and eventually the colobar
    # plot_output[1].savefig(colormap_png_filename)
Ejemplo n.º 7
0
import slam.plot as splt
import slam.io as sio
import slam.remeshing as srem

if __name__ == '__main__':
    # source object files
    source_mesh_file = 'data/example_mesh.gii'
    source_texture_file = 'data/example_texture.gii'
    source_spherical_mesh_file = 'data/example_mesh_spherical.gii'
    # target object files
    target_mesh_file = 'data/example_mesh_2.gii'
    target_spherical_mesh_file = 'data/example_mesh_2_spherical.gii'

    source_mesh = sio.load_mesh(source_mesh_file)
    source_tex = sio.load_texture(source_texture_file)
    source_spherical_mesh = sio.load_mesh(source_spherical_mesh_file)
    splt.pyglet_plot(source_mesh, source_tex.darray[0])
    splt.pyglet_plot(source_spherical_mesh, source_tex.darray[0])

    target_mesh = sio.load_mesh(target_mesh_file)
    target_spherical_mesh = sio.load_mesh(target_spherical_mesh_file)

    interpolated_tex_values = \
        srem.spherical_interpolation_nearest_neigbhor(source_spherical_mesh,
                                                      target_spherical_mesh,
                                                      source_tex.darray[0])
    splt.pyglet_plot(target_mesh, interpolated_tex_values, plot_colormap=True)
Ejemplo n.º 8
0
if __name__ == '__main__':

    mesh = sio.load_mesh('data/example_mesh.gii')
    mesh.apply_transform(mesh.principal_inertia_transform)
    # mesh.show()
    mesh_s = sm.filter_laplacian(mesh.copy(), iterations=100)
    # mesh_s.show()

    print(mesh.vertices.shape)

    angle_diff = sdst.angle_difference(mesh, mesh_s)
    print(angle_diff)

    face_angle_dist = np.sum(np.abs(angle_diff), 1)
    print(face_angle_dist)

    vect_col = np.random.random_integers(0, 255, mesh.faces.shape[0])
    print(vect_col.shape)
    # mesh.visual.vertex_colors = vert_col
    mesh.visual.faces_colors = vect_col
    mesh.show()

    # f, ax = plt.subplots(1,1)
    # ax.set_title('angles')
    # ax.hist(angle_diff.flatten())
    # # axs[3].set_xticks(X_edge)
    # ax.grid(True)
    # plt.show()

    splt.pyglet_plot(mesh_s, face_angle_dist, 'hot', True)
import slam.remeshing as srem
from slam import texture as stex
import matplotlib.pyplot as plt
import scipy.sparse as sp
# from quadrics import *

# Data
data_path = '/hpc/meca/users/souani.a/data'
mesh_file = os.path.join(data_path,'lhwhite.gii')
mesh = sio.load_mesh(mesh_file)
texture_file = os.path.join(data_path,'OASIS_0004_Lwhite_bassins.gii')
texture = sio.load_texture(texture_file)
texture=texture.darray

# Mesh + texture
splt.pyglet_plot(mesh, texture, 'jet', True)

unique_values=np.unique(texture)
print(unique_values)
unique_values=np.setdiff1d(unique_values,0)
print(unique_values)
# Density
for i,val in enumerate(unique_values):
    inds = texture ==val
    sub_meshes, sub_tex, sub_corresp = stop.cut_mesh(mesh, inds)
    print(sub_meshes[0].vertices.shape[0])
    print(sub_meshes[0].area_faces.sum())
    print(sub_meshes[0].vertices.shape[0]/sub_meshes[0].area_faces.sum())

# Sub_meshes