Exemple #1
0
import slam.io as sio
import numpy as np
import trimesh

###############################################################################
# loading an two unregistered meshes
mesh_1 = sio.load_mesh('../examples/data/example_mesh.gii')
mesh_2 = sio.load_mesh('../examples/data/example_mesh_2.gii')

###############################################################################
# plot them to check the misalignment
joint_mesh = mesh_1 + mesh_2
joint_tex = np.ones((joint_mesh.vertices.shape[0], ))
joint_tex[:mesh_1.vertices.shape[0]] = 10
visb_sc = splt.visbrain_plot(mesh=joint_mesh,
                             tex=joint_tex,
                             caption='before registration')
visb_sc.preview()

###############################################################################
# compute ICP registration
transf_mat, cost = trimesh.registration.mesh_other(mesh_1,
                                                   mesh_2,
                                                   samples=500,
                                                   scale=False,
                                                   icp_first=10,
                                                   icp_final=100)
print(transf_mat)
print(cost)

###############################################################################
Exemple #2
0
###############################################################################
# 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)

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])
###############################################################################
# plot
visb_sc = splt.visbrain_plot(mesh=source_mesh, tex=source_tex.darray[0],
                                caption='source with curvature',
                                cblabel='curvature')
visb_sc = splt.visbrain_plot(mesh=source_spherical_mesh,
                                tex=source_tex.darray[0],
                                caption='spherical source mesh',
                                cblabel='curvature', visb_sc=visb_sc)
visb_sc = splt.visbrain_plot(mesh=target_mesh, tex=interpolated_tex_values,
                                caption='target mesh with curvature '
                                        'from source mesh',
                                cblabel='curvature', visb_sc=visb_sc)
visb_sc.preview()
Exemple #3
0
open_mesh = sps.generate_quadric(K, nstep=5)

###############################################################################
# Identify the vertices lying on the boundary of the mesh and order
# them to get a path traveling across boundary vertices
# The output is a list of potentially more than one boudaries
# depending on the topology of the input mesh.
# Here the mesh has a single boundary
open_mesh_boundary = stop.mesh_boundary(open_mesh)
print(open_mesh_boundary)


###############################################################################
# show the result
# WARNING : BrainObj should be added first before
visb_sc = splt.visbrain_plot(mesh=open_mesh, caption='open mesh')
# create points with vispy
for bound in open_mesh_boundary:
    points = open_mesh.vertices[bound]
    s_rad = SourceObj('rad', points, color='red', symbol='square',
                      radius_min=10)
    visb_sc.add_to_subplot(s_rad)
    lines = Line(pos=open_mesh.vertices[bound], width=10, color='b')
    # wrap the vispy object using visbrain
    l_obj = VispyObj('line', lines)
    visb_sc.add_to_subplot(l_obj)
visb_sc.preview()

###############################################################################
# here is how to get the vertices that define the boundary of
# a texture on a mesh
    s_mesh = sdg.laplacian_mesh_smoothing(mesh, nb_iter=100, dt=0.1)

    # compute the gradient of texture tex
    triangle_grad = sdg.triangle_gradient(mesh, tex.darray[0])
    print(triangle_grad)
    grad = sdg.gradient(mesh, tex.darray[0])
    print(grad.values)
    norm_grad = sdg.norm_gradient(mesh, tex.darray[0])
    print(norm_grad)

    # compute the depth potential function
    dpf = sdg.depth_potential_function(mesh, tex.darray[0], [0.3])

    # plot all that to show the results
    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=tex.darray[0],
                                 caption='mesh with curvature',
                                 cblabel='curvature')
    visb_sc = splt.visbrain_plot(mesh=s_mesh,
                                 caption='smoothed mesh',
                                 visb_sc=visb_sc)
    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=norm_grad,
                                 caption='norm of the gradient of curvature',
                                 cblabel='gradient magnitude',
                                 visb_sc=visb_sc)
    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=dpf[0],
                                 caption='depth potential function',
                                 cblabel='dpf',
                                 visb_sc=visb_sc)
    visb_sc.preview()
Exemple #5
0
###############################################################################
# Getting the vertex index in specified geo_distance of vert
vert_id = 200
max_geodist = 10

geo_distance = sgeo.compute_gdist(mesh, vert_id)
area_geodist_vi = np.where(geo_distance < max_geodist)[0]

print(area_geodist_vi)

###############################################################################
# Visualization

visb_sc = splt.visbrain_plot(mesh=mesh, tex=geo_distance,
                             caption='geodesic distance',
                             cblabel='distance')
visb_sc.preview()

###############################################################################
# Getting the vertex index in specified geo_distance of vert

area_geodist = sgeo.local_gdist_matrix(mesh, max_geodist)

visb_sc2 = splt.visbrain_plot(mesh=mesh,
                             tex=area_geodist[0].toarray().squeeze(),
                             caption='local geodesic distance',
                             cblabel='distance')
visb_sc2.preview()
###############################################################################
# Get the vertex index
Exemple #6
0
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)
    print(tex.min())
    print(tex.max())
    visb_sc = splt.visbrain_plot(mesh=mesh, caption='simple mesh')
    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=tex.darray[0],
                                 caption='with curvature',
                                 cblabel='curvature',
                                 visb_sc=visb_sc)
    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=tex.darray[0],
                                 caption='change cmap',
                                 cblabel='curvature',
                                 cmap='hot',
                                 visb_sc=visb_sc)
    visb_sc.preview()
    # then save the 3D rendering figure
    # visb_sc.screenshot('test.png')
    # # most simple mesh visualization
    # splt.pyglet_plot(mesh)
import slam.io as sio
import slam.plot as splt
import slam.vertex_voronoi as svv
import numpy as np

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)

    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=vert_vor,
                                 caption='vertex voronoi',
                                 cblabel='vertex voronoi')
    visb_sc.preview()
Exemple #8
0
    mesh = trimesh.Trimesh(faces=faces_tri.simplices,
                           vertices=coords,
                           process=False)
    return mesh


params = [4, 0.25]
ax = 2
ay = 1
nstep = 50
mesh = boucher_surface(params, ax, ay, nstep)

##########################################################################
# Visualization of the mesh
visb_sc = splt.visbrain_plot(mesh=mesh,
                             caption='Boucher mesh',
                             bgcolor=[0.3, 0.5, 0.7])
visb_sc
visb_sc.preview()

##################################
# Compute dpf for various alpha

res = sc.curvatures_and_derivatives(mesh)
mean_curvature = res[0].sum(axis=0)
alphas = [0.001, 0.01, 0.1, 1, 10, 100]
dpfs = sdg.depth_potential_function(mesh,
                                    curvature=mean_curvature,
                                    alphas=alphas)

amplitude_center = []
Exemple #9
0
import slam.generate_parametric_surfaces as sps
import numpy as np
import slam.topology as stop
import slam.plot as splt
import slam.mapping as smap
import slam.distortion as sdst
from vispy.scene import Line
from visbrain.objects import VispyObj, SourceObj

###############################################################################
# Generation of an open mesh
K = [-1, -1]
open_mesh = sps.generate_quadric(K, nstep=[5, 5])
open_mesh_boundary = stop.mesh_boundary(open_mesh)
# Visualization
visb_sc = splt.visbrain_plot(mesh=open_mesh, caption='open mesh')
for bound in open_mesh_boundary:
    points = open_mesh.vertices[bound]
    s_rad = SourceObj('rad',
                      points,
                      color='red',
                      symbol='square',
                      radius_min=10)
    visb_sc.add_to_subplot(s_rad)
    lines = Line(pos=open_mesh.vertices[bound], width=10, color='b')
    # wrap the vispy object using visbrain
    l_obj = VispyObj('line', lines)
    visb_sc.add_to_subplot(l_obj)
visb_sc.preview()

###############################################################################
===================================
example of hinge shaped surface
===================================
"""

# Authors: Julien Lefevre <*****@*****.**>

# License: BSD (3-clause)
# sphinx_gallery_thumbnail_number = 2

###############################################################################
# importation of slam modules
import slam.plot as splt
import slam.curvature as scurv
import slam.generate_parametric_surfaces as sgps

###############################################################################
# Creating an examplar 3-4-...n hinge mesh

hinge_mesh = sgps.generate_hinge(n_hinge=4)
mesh_curvatures = scurv.curvatures_and_derivatives(hinge_mesh)
mean_curvature = 1 / 2 * mesh_curvatures[0].sum(axis=0)

visb_sc = splt.visbrain_plot(mesh=hinge_mesh,
                             tex=mean_curvature,
                             caption='hinge',
                             cblabel='mean curvature')

visb_sc.preview()
Exemple #11
0
import slam.io as sio
import slam.differential_geometry as sdg
import slam.plot as splt

if __name__ == '__main__':
    mesh = sio.load_mesh('data/example_mesh.gii')
    tex = sio.load_texture('data/example_texture.gii')

    triangle_grad = sdg.triangle_gradient(mesh, tex.darray[0])
    print(triangle_grad)
    grad = sdg.gradient(mesh, tex.darray[0])
    print(grad.values)
    norm_grad = sdg.norm_gradient(mesh, tex.darray[0])
    print(norm_grad)
    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=tex.darray[0],
                                 caption='mesh with curvature',
                                 cblabel='curvature')
    visb_sc = splt.visbrain_plot(mesh=mesh,
                                 tex=norm_grad,
                                 caption='norm of the gradient of curvature',
                                 cblabel='gradient magnitude',
                                 visb_sc=visb_sc)
    visb_sc.preview()

    lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='fem')
    print(mesh.vertices.shape)
    print(lap.shape)
    lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='conformal')
    lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='meanvalue')
    lap, lap_b = sdg.compute_mesh_laplacian(mesh, lap_type='authalic')
Exemple #12
0
    # mesh_boundary works fine
    # here is how to get the vertices that define the boundary of an open mesh
    K = [-1, -1]
    open_mesh = sps.generate_quadric(K, nstep=5)
    print('================= mesh_boundary =================')
    print('Identify the vertices lying on the boundary of the mesh and order'
          'them to get a path traveling across boundary vertices')
    print('The output is a list of potentially more than one boudaries '
          'depending on the topology of the input mesh')
    open_mesh_boundary = stop.mesh_boundary(open_mesh)
    print(open_mesh_boundary)
    print('Here the mesh has a single boundary')

    # WARNING : BrainObj should be added first before
    visb_sc = splt.visbrain_plot(mesh=open_mesh, caption='open mesh')
    # create points with vispy
    for bound in open_mesh_boundary:
        points = open_mesh.vertices[bound]
        s_rad = SourceObj('rad',
                          points,
                          color='red',
                          symbol='square',
                          radius_min=10)
        visb_sc.add_to_subplot(s_rad)
        lines = Line(pos=open_mesh.vertices[bound], width=10, color='b')
        # wrap the vispy object using visbrain
        l_obj = VispyObj('line', lines)
        visb_sc.add_to_subplot(l_obj)
    visb_sc.preview()
Exemple #13
0
        noqq = np.sqrt(np.sum(qq * qq, 1))
        nopp = np.sqrt(np.sum(pp * pp, 1))

        pp = pp / np.vstack((nopp, np.vstack((nopp, nopp)))).transpose()
        qq = qq / np.vstack((noqq, np.vstack((noqq, noqq)))).transpose()
        angles_out[:, i] = np.arccos(np.sum(pp * qq, 1))
    return angles_out


if __name__ == '__main__':
    mesh = sio.load_mesh('data/example_mesh.gii')
    sphere, evol = smap.spherical_mapping(mesh,
                                          mapping_type='conformal',
                                          dt=0.01,
                                          nb_it=3000)
    visb_sc = splt.visbrain_plot(mesh=mesh, caption='original mesh')
    visb_sc = splt.visbrain_plot(mesh=sphere,
                                 caption='spherical representation',
                                 visb_sc=visb_sc)
    visb_sc.preview()

    angle_diff = sdst.angle_difference(sphere, mesh)
    area_diff = sdst.area_difference(sphere, mesh)
    edge_diff = sdst.edge_length_difference(sphere, mesh)

    aevol = np.array(evol)
    f, ax = plt.subplots(1, 3)
    ax[0].set_title('angles')
    # ax[0].hist(angle_diff.flatten())
    ax[0].plot(aevol[:, 0])
    ax[0].grid(True)
Exemple #14
0
# Generating a quadrix surface

K = [1, 1]
quadric = sgps.generate_quadric(K,
                                nstep=20,
                                ax=3,
                                ay=1,
                                random_sampling=True,
                                ratio=0.3,
                                random_distribution_type='gamma')
quadric_mean_curv = \
    sgps.quadric_curv_mean(K)(np.array(quadric.vertices[:, 0]),
                              np.array(quadric.vertices[:, 1]))

visb_sc = splt.visbrain_plot(mesh=quadric,
                             tex=quadric_mean_curv,
                             caption='quadric',
                             cblabel='mean curvature')

visb_sc.preview()

###############################################################################
# Generating an ellipsiods

nstep = 50
randomSampling = True
a = 2
b = 1
ellips = sgps.generate_ellipsiod(a, b, nstep, randomSampling)

visb_sc = splt.visbrain_plot(mesh=ellips, caption='ellipsoid', visb_sc=visb_sc)
Exemple #15
0
###############################################################################
# Comptue estimations of principal curvatures
PrincipalCurvatures, PrincipalDir1, PrincipalDir2 = \
    scurv.curvatures_and_derivatives(mesh)

###############################################################################
# Comptue Gauss curvature from principal curvatures
gaussian_curv = PrincipalCurvatures[0, :] * PrincipalCurvatures[1, :]

###############################################################################
# Comptue mean curvature from principal curvatures
mean_curv = 0.5 * (PrincipalCurvatures[0, :] + PrincipalCurvatures[1, :])

###############################################################################
# Plot mean curvature
visb_sc = splt.visbrain_plot(mesh=mesh,
                             tex=mean_curv,
                             caption='mean curvature',
                             cblabel='mean curvature')
visb_sc.preview()

###############################################################################
# PLot Gauss curvature
visb_sc = splt.visbrain_plot(mesh=mesh,
                             tex=gaussian_curv,
                             caption='Gaussian curvature',
                             cblabel='Gaussian curvature',
                             cmap='hot')
visb_sc.preview()
Exemple #16
0
# Importation of slam modules
import slam.distortion as sdst
import slam.differential_geometry as sdg
import slam.plot as splt
import slam.io as sio
import numpy as np

###############################################################################
# Loading an example mesh and a smoothed copy of it

mesh = sio.load_mesh('data/example_mesh.gii')
mesh_s = sdg.laplacian_mesh_smoothing(mesh, nb_iter=50, dt=0.1)

################################################################################
# Visualization of the original mesh
visb_sc = splt.visbrain_plot(mesh=mesh, caption='original mesh')
visb_sc.preview()

###############################################################################
# Visualization of the smoothed mesh
visb_sc = splt.visbrain_plot(mesh=mesh_s,
                             caption='smoothed mesh',
                             visb_sc=visb_sc)
visb_sc.preview()

###############################################################################
# Computation of the angle difference between each faces of mesh and mesh_s
angle_diff = sdst.angle_difference(mesh, mesh_s)
angle_diff

###############################################################################
Exemple #17
0
# Comptue estimations of principal curvatures
PrincipalCurvatures, PrincipalDir1, PrincipalDir2 = \
    scurv.curvatures_and_derivatives(mesh)

###############################################################################
# Comptue Gauss curvature from principal curvatures
gaussian_curv = PrincipalCurvatures[0, :] * PrincipalCurvatures[1, :]

###############################################################################
# Comptue mean curvature from principal curvatures
mean_curv = 0.5 * (PrincipalCurvatures[0, :] + PrincipalCurvatures[1, :])

###############################################################################
# Plot mean curvature
visb_sc = splt.visbrain_plot(mesh=mesh,
                             tex=mean_curv,
                             caption='mean curvature',
                             cblabel='mean curvature')
visb_sc.preview()

###############################################################################
# Plot Gauss curvature
visb_sc = splt.visbrain_plot(mesh=mesh,
                             tex=gaussian_curv,
                             caption='Gaussian curvature',
                             cblabel='Gaussian curvature',
                             cmap='hot')
visb_sc.preview()

###############################################################################
# Decomposition of the curvatures into ShapeIndex and Curvedness
# Based on 'Surface shape and curvature scales