From bf16ce747403404a1ecb3d7995700fa2f8e7480a Mon Sep 17 00:00:00 2001 From: Maxime Van Der Valk Date: Fri, 30 Jan 2026 09:09:10 +0100 Subject: [PATCH 1/3] new examples plus correction lighting effects plot --- examples/example_curvature.py | 20 +++++++--- examples/example_distortion.py | 62 +++++++++++++++++++++++++++--- examples/example_topology.py | 14 ++++--- examples/example_vertex_voronoi.py | 4 +- slam/plot.py | 29 +++++++------- 5 files changed, 96 insertions(+), 33 deletions(-) diff --git a/examples/example_curvature.py b/examples/example_curvature.py index 6a235af1..0b090e37 100644 --- a/examples/example_curvature.py +++ b/examples/example_curvature.py @@ -146,9 +146,11 @@ ) angular_error_1 = 180 * angular_error_1 / np.pi + ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + import slam.plot as splt vertices = mesh.vertices @@ -161,10 +163,12 @@ [0, np.cos(theta), -np.sin(theta)], [0, np.sin(theta), np.cos(theta)]]) vertices_translate = np.dot(rot_x, vertices_translate.T).T -rot_z = np.array([[np.cos(theta), -np.sin(theta),0], - [np.sin(theta), np.cos(theta),0], - [0, 0, 1],]) +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature display_settings = {} display_settings['colorbar_label'] = 'Mean Curvature' mesh_data = {} @@ -180,6 +184,7 @@ display_settings=display_settings) Fig.show() +# Plot Gaussian Curvature mesh_data['title'] = 'example_mesh.gii Gaussian Curvature' intensity_data['values'] = gaussian_curv display_settings['colorbar_label'] = 'Gaussian Curvature' @@ -189,6 +194,7 @@ display_settings=display_settings) Fig.show() +# Plot Shape Index mesh_data['title'] = 'example_mesh.gii Shape Index' intensity_data['values'] = shapeIndex display_settings['colorbar_label'] = 'Shape Index' @@ -198,6 +204,7 @@ display_settings=display_settings) Fig.show() +# Plot Curvedness mesh_data['title'] = 'example_mesh.gii Curvedness' intensity_data['values'] = curvedness display_settings['colorbar_label'] = 'Curvedness' @@ -207,6 +214,7 @@ display_settings=display_settings) Fig.show() +# Plot Quadric K Mean Absolute Change mesh_data['vertices'] = quadric.vertices mesh_data['faces'] = quadric.faces mesh_data['title'] = 'Quadric K Mean Absolute Change' @@ -218,6 +226,7 @@ display_settings=display_settings) Fig.show() +# Plot Quadric Angular Error 0 mesh_data['title'] = 'Quadric Angular Error 0' intensity_data['values'] = angular_error_0 display_settings['colorbar_label'] = 'Angular Error 0' @@ -227,7 +236,8 @@ display_settings=display_settings) Fig.show() -mesh_data['title'] = ('Quadric Angular Error 1') +# Plot Quadric Angular Error 1 +mesh_data['title'] = 'Quadric Angular Error 1' intensity_data['values'] = angular_error_1 display_settings['colorbar_label'] = 'Angular Error 1' Fig = splt.mes3d_projection( diff --git a/examples/example_distortion.py b/examples/example_distortion.py index 02077f4d..3ee4fdc4 100644 --- a/examples/example_distortion.py +++ b/examples/example_distortion.py @@ -52,13 +52,65 @@ edge_diff = sdst.edge_length_difference(mesh, mesh_s) edge_diff + ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + +import slam.plot as splt + # # Visualization of the original mesh -# visb_sc = splt.visbrain_plot(mesh=mesh, caption="original mesh") -# visb_sc.preview() +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1],]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Original Mesh' +intensity_data = None +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + # ############################################################################ # # Visualization of the smoothed mesh -# visb_sc = splt.visbrain_plot(mesh=mesh_s, caption="smoothed mesh") -# visb_sc.preview() + +vertices = mesh_s.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1],]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh_s.faces +mesh_data['title'] = 'example_mesh.gii Smoothed Mesh' +intensity_data = None +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() diff --git a/examples/example_topology.py b/examples/example_topology.py index 1f3052cb..7beaaf2f 100644 --- a/examples/example_topology.py +++ b/examples/example_topology.py @@ -92,6 +92,14 @@ print(mesh.is_watertight) print(mesh_closed.is_watertight) + +print('close mesh') +broken_vertices_mesh_closed = stop.broken_vertices(mesh_closed) +print(np.count_nonzero(broken_vertices_mesh_closed)) +print('open mesh') +broken_vertices_open_mesh = stop.broken_vertices(open_mesh) +print(np.count_nonzero(broken_vertices_open_mesh)) + ############################################################################# # VISUALIZATION USING EXTERNAL TOOLS ############################################################################# @@ -222,9 +230,3 @@ # visb_sc5 = splt.visbrain_plot(mesh=mesh_closed, caption="closed mesh") # visb_sc5.preview() -print('close mesh') -broken_vertices = stop.broken_vertices(mesh_closed) -print(np.count_nonzero(broken_vertices)) -print('open mesh') -broken_vertices = stop.broken_vertices(open_mesh) -print(np.count_nonzero(broken_vertices)) diff --git a/examples/example_vertex_voronoi.py b/examples/example_vertex_voronoi.py index 47377b51..8e843236 100644 --- a/examples/example_vertex_voronoi.py +++ b/examples/example_vertex_voronoi.py @@ -36,9 +36,11 @@ print(vert_vor.shape) print(np.sum(vert_vor) - mesh.area) + ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + import slam.plot as splt ############################################################################### # Visualization diff --git a/slam/plot.py b/slam/plot.py index 8c28503c..a1686c9f 100755 --- a/slam/plot.py +++ b/slam/plot.py @@ -73,14 +73,15 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): faces = mesh_data["faces"] title = mesh_data.get("title", "") - lighting = { - "ambient": 0.7, - "diffuse": 0.8, - "specular": 0.5, - "roughness": 0.2, - "fresnel": 0.1, - } - + lighting_effects = ( + dict(ambient=0.4, + diffuse=0.5, + roughness=0.9, + specular=0.6, + fresnel=0.2)) + lightposition = dict( + x=-10, y=10, z=10 + ) mesh_kwargs = { "x": vertices[:, 0], "y": vertices[:, 1], @@ -90,7 +91,8 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): "k": faces[:, 2], "color": "ghostwhite", "flatshading": False, - "lighting": lighting, + "lighting": lighting_effects, + "lightposition": lightposition, } if intensity_data is not None: @@ -107,13 +109,8 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): "tickfont": {"size": 16}, }, "flatshading": True, - "lighting": { - "ambient": 1, - "diffuse": 0, - "specular": 0, - "roughness": 1, - "fresnel": 0, - }, + "lighting": lighting_effects, + "lightposition": lightposition, "colorbar_tickvals": display_settings.get("tickvals", None), "colorbar_ticktext": display_settings.get("ticktext", None), }) From 2d5b137e223175d281b35ced1defee62514d0024 Mon Sep 17 00:00:00 2001 From: Maxime Van Der Valk Date: Fri, 30 Jan 2026 09:30:31 +0100 Subject: [PATCH 2/3] new examples --- examples/example_texture.py | 2 +- examples/example_topology.py | 70 +++++++++++++++++++++++++++++++++--- examples/test.gii | 9 ----- slam/plot.py | 31 ++++++++-------- 4 files changed, 83 insertions(+), 29 deletions(-) delete mode 100644 examples/test.gii diff --git a/examples/example_texture.py b/examples/example_texture.py index 4d077007..34d8ed3b 100755 --- a/examples/example_texture.py +++ b/examples/example_texture.py @@ -80,6 +80,6 @@ intensity_data, display_settings, ) - +fig.show() #os.makedirs(PATH, exist_ok=True) #fig.write_image(SAVE_DIR, width=1600, height=900) diff --git a/examples/example_topology.py b/examples/example_topology.py index 7beaaf2f..37d48691 100644 --- a/examples/example_topology.py +++ b/examples/example_topology.py @@ -101,12 +101,72 @@ print(np.count_nonzero(broken_vertices_open_mesh)) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# import slam.plot as splt -# from vispy.scene import Line -# from visbrain.objects import VispyObj, SourceObj -# + +import slam.plot as splt + +vertices = mesh_closed.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +display_settings['colorbar_label'] = 'Broken Vertices' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh_closed.faces +mesh_data['title'] = 'Mesh Close' +intensity_data = {} +intensity_data['values'] = broken_vertices_mesh_closed +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + + +vertices = open_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +display_settings['colorbar_label'] = 'Broken Vertices' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = open_mesh.faces +mesh_data['title'] = 'Mesh Close' +intensity_data = {} +intensity_data['values'] = broken_vertices_open_mesh +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() # ############################################################################### # # show the result # # WARNING : BrainObj should be added first before diff --git a/examples/test.gii b/examples/test.gii deleted file mode 100644 index 841a02eb..00000000 --- a/examples/test.gii +++ /dev/null @@ -1,9 +0,0 @@ - - -NIFTI_XFORM_UNKNOWNNIFTI_XFORM_UNKNOWN 1.000000 0.000000 0.000000 0.000000 - 0.000000 1.000000 0.000000 0.000000 - 0.000000 0.000000 1.000000 0.000000 - 0.000000 0.000000 0.000000 1.000000eJxjYEAAAAAMAAE=NIFTI_XFORM_UNKNOWNNIFTI_XFORM_UNKNOWN 1.000000 0.000000 0.000000 0.000000 - 0.000000 1.000000 0.000000 0.000000 - 0.000000 0.000000 1.000000 0.000000 - 0.000000 0.000000 0.000000 1.000000eJxjYEAAAAAMAAE= \ No newline at end of file diff --git a/slam/plot.py b/slam/plot.py index a1686c9f..1c7ccd0c 100755 --- a/slam/plot.py +++ b/slam/plot.py @@ -73,15 +73,14 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): faces = mesh_data["faces"] title = mesh_data.get("title", "") - lighting_effects = ( - dict(ambient=0.4, - diffuse=0.5, - roughness=0.9, - specular=0.6, - fresnel=0.2)) - lightposition = dict( - x=-10, y=10, z=10 - ) + lighting = { + "ambient": 0.7, + "diffuse": 0.8, + "specular": 0.5, + "roughness": 0.2, + "fresnel": 0.1, + } + mesh_kwargs = { "x": vertices[:, 0], "y": vertices[:, 1], @@ -91,8 +90,7 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): "k": faces[:, 2], "color": "ghostwhite", "flatshading": False, - "lighting": lighting_effects, - "lightposition": lightposition, + "lighting": lighting, } if intensity_data is not None: @@ -109,8 +107,13 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): "tickfont": {"size": 16}, }, "flatshading": True, - "lighting": lighting_effects, - "lightposition": lightposition, + "lighting": { + "ambient": 1, + "diffuse": 0, + "specular": 0, + "roughness": 1, + "fresnel": 0, + }, "colorbar_tickvals": display_settings.get("tickvals", None), "colorbar_ticktext": display_settings.get("ticktext", None), }) @@ -140,4 +143,4 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): }, ) - return fig + return fig \ No newline at end of file From 8d9eea6994199ee481eb02f3f2fbb1774f470fe9 Mon Sep 17 00:00:00 2001 From: Maxime Van Der Valk Date: Fri, 30 Jan 2026 16:07:48 +0100 Subject: [PATCH 3/3] visu examples --- examples/example_differential_geometry.py | 87 +++--- examples/example_distortion.py | 8 +- examples/example_dpf_Boucher.py | 100 +++---- .../example_generate_parametric_surfaces.py | 104 ++++++- examples/example_geodesic.py | 67 +++-- examples/example_hinge_gyri.py | 35 ++- examples/example_registration.py | 82 ++++-- examples/example_remeshing.py | 96 +++++-- examples/example_spangy.py | 63 +++-- examples/example_topology.py | 267 ++++++++++++++---- examples/example_transfo_mesh.py | 63 +++++ 11 files changed, 711 insertions(+), 261 deletions(-) create mode 100644 examples/example_transfo_mesh.py diff --git a/examples/example_differential_geometry.py b/examples/example_differential_geometry.py index e09e60bf..94b7b67e 100644 --- a/examples/example_differential_geometry.py +++ b/examples/example_differential_geometry.py @@ -21,7 +21,7 @@ # importation of slam modules import slam.io as sio import slam.differential_geometry as sdg - +import numpy as np ############################################################################### # loading an examplar mesh and corresponding texture mesh_file = "../examples/data/example_mesh.gii" @@ -52,37 +52,56 @@ print(norm_grad) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# # import visbrain # visu using visbrain -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=tex.darray[0], -# caption="mesh with curvature", cblabel="curvature" -# ) -# visb_sc.preview() -# ############################################################################### -# # show the smoothed mesh -# visb_sc = splt.visbrain_plot( -# mesh=s_mesh, -# caption="smoothed mesh" -# ) -# visb_sc.preview() -# ############################################################################### -# # show the norm of the gradient of the curvature -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=norm_grad, -# caption="norm of the gradient of curvature", -# cblabel="gradient magnitude", -# ) -# visb_sc.preview() -# ############################################################################### -# # show the depth potential function -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=dpf[0], -# caption="depth potential function", -# cblabel="dpf" -# ) -# visb_sc.preview() + +import slam.plot as splt + +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Original Mesh +display_settings = {} +display_settings['colorbar_label'] = 'Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Mean Curvature' +intensity_data = {} +intensity_data['values'] = tex.darray[0] +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + +# Show the Norm of the Gradient of the Curvature +display_settings = {} +display_settings['colorbar_label'] = 'Gradient Magnitude' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Norm of the Gradient of Curvature' +intensity_data = {} +intensity_data['values'] = norm_grad +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + diff --git a/examples/example_distortion.py b/examples/example_distortion.py index 3ee4fdc4..df80fe00 100644 --- a/examples/example_distortion.py +++ b/examples/example_distortion.py @@ -94,15 +94,9 @@ vertices = vertices - np.mean(vertices, axis=0) vertices_translate = np.copy(vertices) # rotate the vertices -theta = np.pi / 2 -rot_x = np.array([[1, 0, 0], - [0, np.cos(theta), -np.sin(theta)], - [0, np.sin(theta), np.cos(theta)]]) vertices_translate = np.dot(rot_x, vertices_translate.T).T -rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], - [np.sin(theta), np.cos(theta), 0], - [0, 0, 1],]) vertices_translate = np.dot(rot_z, vertices_translate.T).T + display_settings = {} mesh_data = {} mesh_data['vertices'] = vertices_translate diff --git a/examples/example_dpf_Boucher.py b/examples/example_dpf_Boucher.py index 141bd26e..e8daabf2 100644 --- a/examples/example_dpf_Boucher.py +++ b/examples/example_dpf_Boucher.py @@ -80,17 +80,17 @@ def boucher_surface(params, ax, ay, nstep): ################################## # Compute dpf for various alpha + alphas = [0.001, 0.01, 0.1, 1, 10, 100] -dpfs = sdepth.depth_potential_function( - mesh, alphas=alphas) +various_dpfs=sdepth.depth_potential_function(mesh, alphas=alphas) amplitude_center = [] amplitude_peak = [] index_peak_pos = np.argmax(mesh.vertices[:, 2]) index_peak_neg = np.argmin(mesh.vertices[:, 2]) -for i in range(len(dpfs)): - amplitude_center.append(dpfs[i][index_peak_neg]) - amplitude_peak.append(dpfs[i][index_peak_pos]) +for i in range(len(various_dpfs)): + amplitude_center.append(various_dpfs[i][index_peak_neg]) + amplitude_peak.append(various_dpfs[i][index_peak_pos]) #################################### # Fix alpha and vary M = params[0] @@ -104,47 +104,51 @@ def boucher_surface(params, ax, ay, nstep): all_amplitudes.append(dpfs[0][len(mesh.vertices) // 2]) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# import visbrain # visu using visbrain -# import slam.plot as splt -# import matplotlib.pyplot as plt -########################################################################## -# # 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() -############################################################################### -# plt.figure() -# plt.semilogx(alphas, amplitude_center) -# plt.semilogx(alphas, amplitude_peak) -# plt.semilogx(alphas, len(alphas) * -# [params[0] * (1 + 2 * np.exp(-3 / 2))], "--") -# plt.xlabel("alpha") -# plt.ylabel("amplitude") -# plt.legend(["DPF at center", "DPF (secondary peaks)", "True amplitude"]) -# plt.show() -# -###################################### -# # Display dpfs on the surfaces -# -# visb_sc = splt.visbrain_plot( -# mesh=mesh, tex=dpfs[0], caption="Boucher mesh", bgcolor="white" -# ) -# visb_sc = splt.visbrain_plot( -# mesh=mesh, tex=dpfs[5], caption="Boucher mesh", visb_sc=visb_sc -# ) -# visb_sc.preview() -# -############################################################################## -# plt.figure() -# plt.plot(all_M, all_amplitudes, "+-") -# plt.xlabel("M") -# plt.ylabel("Amplitude of DPF") -# plt.show() + +import slam.plot as splt + +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1],]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Boucher mesh alpha 0.001' +intensity_data = {} +intensity_data['values'] = various_dpfs[0] +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Boucher mesh alpha 100' +intensity_data = {} +intensity_data['values'] = various_dpfs[5] +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + diff --git a/examples/example_generate_parametric_surfaces.py b/examples/example_generate_parametric_surfaces.py index 0f12d7ee..5df0df47 100644 --- a/examples/example_generate_parametric_surfaces.py +++ b/examples/example_generate_parametric_surfaces.py @@ -74,21 +74,101 @@ ) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# # import visbrain # visu using visbrain -# # show the quadric with its mean curvature -# visb_sc = splt.visbrain_plot( -# mesh=quadric, -# tex=quadric_mean_curv, -# caption="quadric", -# cblabel="mean curvature" -# ) + + +import slam.plot as splt + +vertices = quadric.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +display_settings['colorbar_label'] = 'Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = quadric.faces +mesh_data['title'] = 'Mean Curvature' +intensity_data = {} +intensity_data['values'] = quadric_mean_curv +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + # # show the ellipsoid -# visb_sc = splt.visbrain_plot(mesh=ellips, caption="ellipsoid") + +vertices = ellips.vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +intensity_data=None +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = ellips.faces +mesh_data['title'] = 'Ellips Mesh' +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + # # show the sphere with regular sampling -# visb_sc = splt.visbrain_plot(mesh=sphere_regular, caption="sphere_regular") -# # show the sphere with random sampling +vertices = sphere_regular.vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +intensity_data=None +display_settings['colorbar_label'] = 'Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = sphere_regular.faces +mesh_data['title'] = 'Sphere Regular Mesh' +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + +# # show the sphere with regular sampling +vertices = sphere_random.vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +intensity_data=None +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = sphere_random.faces +mesh_data['title'] = 'Sphere Random Mesh' +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + # visb_sc = splt.visbrain_plot( # mesh=sphere_random, caption="sphere_random", visb_sc=visb_sc # ) diff --git a/examples/example_geodesic.py b/examples/example_geodesic.py index ca134593..ebe7dbc6 100644 --- a/examples/example_geodesic.py +++ b/examples/example_geodesic.py @@ -59,25 +59,48 @@ print(path) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# # Visualization with visbrain -# # show the geodesic distance -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=geo_distance, -# caption="geodesic distance", -# cblabel="distance" -# ) -# visb_sc.preview() -# # show the geodesic distance locally -# visb_sc2 = splt.visbrain_plot( -# mesh=mesh, -# tex=area_geodist[0].toarray().squeeze(), -# caption="local geodesic distance", -# cblabel="distance", -# ) -# visb_sc2.preview() + +import slam.plot as splt + +mesh.apply_transform(mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, mesh.vertices.T).T + +display_settings = {} +display_settings['colorbar_label'] = 'Distance' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Geodesic Distance' +intensity_data = {} +intensity_data['values'] = geo_distance +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + +display_settings = {} +display_settings['colorbar_label'] = 'Distance' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Local Geodesic Distance' +intensity_data = {} +intensity_data['values'] = area_geodist[0].toarray().squeeze() +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + ############################################################################### # # Visualization using pyglet @@ -89,11 +112,11 @@ # # path_visual = trimesh.load_path(mesh.vertices[path]) # path_visual -# -# ############################################################################### -# # Visualizable two points + +############################################################################### +# Visualizable two points # points_visual = trimesh.points.PointCloud(mesh.vertices[[start, end]]) -# + # ############################################################################### # # Create a scene with the mesh, path, and points # diff --git a/examples/example_hinge_gyri.py b/examples/example_hinge_gyri.py index 08ec90d2..dff4097e 100644 --- a/examples/example_hinge_gyri.py +++ b/examples/example_hinge_gyri.py @@ -21,6 +21,7 @@ # importation of slam modules import slam.curvature as scurv import slam.generate_parametric_surfaces as sgps +import numpy as np ############################################################################### # Creating an examplar 3-4-...n hinge mesh @@ -29,13 +30,29 @@ mean_curvature = 1 / 2 * mesh_curvatures[0].sum(axis=0) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS # ############################################################################# -# # Visualization with visbrain -# visb_sc = splt.visbrain_plot( -# mesh=hinge_mesh, -# tex=mean_curvature, -# caption="hinge", -# cblabel="mean curvature" -# ) -# visb_sc.preview() + +import slam.plot as splt + +hinge_mesh.apply_transform(hinge_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, hinge_mesh.vertices.T).T + +display_settings = {} +display_settings['colorbar_label'] = 'Mean Curvature' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = hinge_mesh.faces +mesh_data['title'] = 'Hinge' +intensity_data = {} +intensity_data['values'] = mean_curvature +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() diff --git a/examples/example_registration.py b/examples/example_registration.py index 851fb20e..d27384d2 100644 --- a/examples/example_registration.py +++ b/examples/example_registration.py @@ -11,17 +11,11 @@ # License: MIT # sphinx_gallery_thumbnail_number = 2 -############################################################################### -# NOTE: there is no visualization tool in slam, but we provide at the -# end of this script exemplare code to do the visualization with -# an external solution -############################################################################### - ############################################################################### # importation of slam modules import slam.io as sio import trimesh - +import numpy as np ############################################################################### # loading an two unregistered meshes mesh_1 = sio.load_mesh("../examples/data/example_mesh.gii") @@ -36,29 +30,59 @@ print(transf_mat) print(cost) +############################################################################# +# VISUALIZATION USING INTERNAL TOOLS +############################################################################# + +# # 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 + + +import slam.plot as splt + +joint_mesh.apply_transform(joint_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, joint_mesh.vertices.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = joint_mesh.faces +mesh_data['title'] = 'Before Registration' +intensity_data = {} +intensity_data['values'] = joint_tex +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + ############################################################################### # apply the estimated rigid transformation to the mesh mesh_1.apply_transform(transf_mat) +joint_mesh = mesh_1 + mesh_2 +joint_tex = np.ones((joint_mesh.vertices.shape[0],)) +joint_tex[: mesh_1.vertices.shape[0]] = 10 +joint_mesh.apply_transform(joint_mesh.principal_inertia_transform) +vertices_translate = np.dot(rot_x, joint_mesh.vertices.T).T -############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS -############################################################################# -# # Visualization with visbrain -# import slam.plot as splt -# import numpy as np -# ############################################################################### -# # 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() -# ############################################################################### -# # plot the two meshes to check they are now aligned -# joint_mesh = mesh_1 + mesh_2 -# visb_sc = splt.visbrain_plot( -# mesh=joint_mesh, tex=joint_tex, caption="after registration" -# ) -# visb_sc.preview() +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = joint_mesh.faces +mesh_data['title'] = 'After Registration' +intensity_data = {} +intensity_data['values'] = joint_tex +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() diff --git a/examples/example_remeshing.py b/examples/example_remeshing.py index 92fab963..5c0bcc26 100644 --- a/examples/example_remeshing.py +++ b/examples/example_remeshing.py @@ -23,7 +23,7 @@ # Importation of slam modules import slam.io as sio import slam.remeshing as srem - +import numpy as np ############################################################################### # Source object files source_mesh_file = "../examples/data/example_mesh.gii" @@ -47,29 +47,79 @@ ) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# + +import slam.plot as splt + +source_mesh.apply_transform(source_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, source_mesh.vertices.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = source_mesh.faces +mesh_data['title'] = 'Source' +intensity_data = {} +intensity_data['values'] = source_tex.darray[0], +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + # # Visualization with visbrain # import slam.plot as splt # ############################################################################### -# 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() + +source_spherical_mesh.apply_transform(source_spherical_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, source_spherical_mesh.vertices.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = source_spherical_mesh.faces +mesh_data['title'] = 'Spherical Source' +intensity_data = {} +intensity_data['values'] = source_tex.darray[0], +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + +target_mesh.apply_transform(target_mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, target_mesh.vertices.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = target_mesh.faces +mesh_data['title'] = 'target mesh from source mesh' +intensity_data = {} +intensity_data['values'] = interpolated_tex_values, +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + diff --git a/examples/example_spangy.py b/examples/example_spangy.py index a9df385d..98aaa4bb 100644 --- a/examples/example_spangy.py +++ b/examples/example_spangy.py @@ -83,7 +83,7 @@ eigVects) -# WHOLE BRAIN MEAN-CURVATURE<=0 & MEAN-CURVATURE>0 SPECTRI +# WHOLE BRAIN MEAN-CURVATURE<=0 & MEAN-CURVATURE>0 SPECTRE # -------------------------------------------------------- # Define negative mean curvature subsignal mean_curv_sulci = np.zeros((mean_curv.shape)) @@ -98,22 +98,34 @@ = spgy.spectrum(mean_curv_gyri, lap_b, eigVects, eigVal) ############################################################################# -# VISUALIZATION USING EXTERNAL TOOLS +# VISUALIZATION USING INTERNAL TOOLS ############################################################################# -# import slam.plot as splt -# import matplotlib.pyplot as plt -# from matplotlib.colors import ListedColormap -# import pyvista as pv -# -# ############################################################################### -# # Plot of mean curvature on the mesh -# visb_sc = splt.visbrain_plot( -# mesh=mesh, -# tex=mean_curv, -# caption='Mean Curvature', -# cmap='jet') -# visb_sc.preview() -# + + +import slam.plot as splt + +mesh.apply_transform(mesh.principal_inertia_transform) +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, mesh.vertices.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Mean Curvature' +intensity_data = {} +intensity_data['values'] = mean_curv +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + # # Plot coefficients and bands for all mean curvature signal # fig, (ax1, ax2) = plt.subplots(1, 2) # ax1.scatter(np.sqrt(eigVal/2*np.pi), @@ -132,11 +144,20 @@ # ax2.set_ylabel('Power Spectrum') # plt.show() # -# # Plot of spectral dominant bands on the mesh -# visb_sc = splt.visbrain_plot(mesh=mesh, tex=loc_dom_band, -# caption='Local Dominant Band', cmap='jet') -# visb_sc.preview() -# + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = ('Local Dominant Band') +intensity_data = {} +intensity_data['values'] = loc_dom_band +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() # # Plot mean curvature coefficients & compacted power spectrum characterizing # # either Sulci either Gyri folding pattern # # --------------------------------------------------------------------------- diff --git a/examples/example_topology.py b/examples/example_topology.py index 37d48691..731c5bce 100644 --- a/examples/example_topology.py +++ b/examples/example_topology.py @@ -106,7 +106,7 @@ import slam.plot as splt -vertices = mesh_closed.vertices +vertices = open_mesh.vertices # center the vertices vertices = vertices - np.mean(vertices, axis=0) vertices_translate = np.copy(vertices) @@ -123,14 +123,11 @@ # Plot Mean Curvature display_settings = {} -display_settings['colorbar_label'] = 'Broken Vertices' mesh_data = {} mesh_data['vertices'] = vertices_translate -mesh_data['faces'] = mesh_closed.faces -mesh_data['title'] = 'Mesh Close' -intensity_data = {} -intensity_data['values'] = broken_vertices_mesh_closed -intensity_data["mode"] = "vertex" +mesh_data['faces'] = open_mesh.faces +mesh_data['title'] = 'Open Mesh' +intensity_data = None Fig = splt.mes3d_projection( mesh_data=mesh_data, intensity_data=intensity_data, @@ -138,8 +135,27 @@ Fig.show() - -vertices = open_mesh.vertices +# ############################################################################### +# # show the result +# # 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() +# +# ############################################################################### +# # show the result +vertices = eroded_mesh.vertices # center the vertices vertices = vertices - np.mean(vertices, axis=0) vertices_translate = np.copy(vertices) @@ -153,42 +169,20 @@ [np.sin(theta), np.cos(theta), 0], [0, 0, 1], ]) vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature display_settings = {} -display_settings['colorbar_label'] = 'Broken Vertices' mesh_data = {} mesh_data['vertices'] = vertices_translate -mesh_data['faces'] = open_mesh.faces -mesh_data['title'] = 'Mesh Close' -intensity_data = {} -intensity_data['values'] = broken_vertices_open_mesh -intensity_data["mode"] = "vertex" +mesh_data['faces'] = eroded_mesh.faces +mesh_data['title'] = 'Eroded Mesh' +intensity_data = None Fig = splt.mes3d_projection( mesh_data=mesh_data, intensity_data=intensity_data, display_settings=display_settings) Fig.show() -# ############################################################################### -# # 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() -# -# ############################################################################### -# # show the result + # visb_sc2 = splt.visbrain_plot(mesh=eroded_mesh, caption="eroded mesh") # # show again the boundary of original mesh which have been removed with # # corresponding faces by the erosion @@ -209,8 +203,37 @@ # # ############################################################################### # # show the results -# visb_sc3 = splt.visbrain_plot( -# mesh=mesh, tex=tex_parcel.darray[0], caption="texture boundary" + + # show the result +vertices = mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'Texture Boundary' +intensity_data = {} +intensity_data['values'] = tex_parcel.darray[0] +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() # ) # cols = ["red", "green", "yellow", "blue"] # ind = 0 @@ -234,20 +257,45 @@ # # ############################################################################### # # show the mesh with the cuted subparts in different colors -# scene_list = list() -# cuted_mesh = sub_meshes[-1] -# joint_mesh = sub_meshes[0] -# joint_tex = np.zeros((sub_meshes[0].vertices.shape[0],)) -# last_ind = sub_meshes[0].vertices.shape[0] -# for ind, sub_mesh in enumerate(sub_meshes[1:]): -# sub_tex = np.ones((sub_mesh.vertices.shape[0],)) * (ind + 1) -# joint_mesh += sub_mesh -# joint_tex = np.hstack((joint_tex, sub_tex)) -# visb_sc3 = splt.visbrain_plot( -# mesh=joint_mesh, -# tex=joint_tex, -# caption="mesh parts shown in different colors" -# ) +scene_list = list() +cuted_mesh = sub_meshes[-1] +joint_mesh = sub_meshes[0] +joint_tex = np.zeros((sub_meshes[0].vertices.shape[0],)) +last_ind = sub_meshes[0].vertices.shape[0] +for ind, sub_mesh in enumerate(sub_meshes[1:]): + sub_tex = np.ones((sub_mesh.vertices.shape[0],)) * (ind + 1) + joint_mesh += sub_mesh + joint_tex = np.hstack((joint_tex, sub_tex)) + +vertices = joint_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = joint_mesh.faces +mesh_data['title'] = 'mesh parts shown in different colors' +intensity_data = {} +intensity_data['values'] = joint_tex +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + # ind = 0 # boundaries = stop.mesh_boundary(cuted_mesh) # for bound in boundaries: @@ -268,8 +316,38 @@ # ind = 0 # visb_sc3.preview() # ############################################################################### + + + # # show the largest submesh with the boundaries of cutted parts -# visb_sc4 = splt.visbrain_plot(mesh=cuted_mesh, caption="open mesh") +vertices = cuted_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = cuted_mesh.faces +mesh_data['title'] = 'Open Mesh' +intensity_data = None +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + # # create points with vispy # for bound in boundaries: # points = cuted_mesh.vertices[bound] @@ -287,6 +365,83 @@ # visb_sc4.preview() # ############################################################################### # # show the closed mesh -# visb_sc5 = splt.visbrain_plot(mesh=mesh_closed, caption="closed mesh") -# visb_sc5.preview() + + +# # show the largest submesh with the boundaries of cutted parts +vertices = mesh_closed.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) +vertices_translate = np.dot(rot_x, vertices_translate.T).T +rot_z = np.array([[np.cos(theta), -np.sin(theta), 0], + [np.sin(theta), np.cos(theta), 0], + [0, 0, 1], ]) +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh_closed.faces +mesh_data['title'] = 'Closed Mesh' +intensity_data = None +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() +###########################################################" +# Plot the broken vertices + +vertices = mesh_closed.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T + +# Plot Mean Curvature +display_settings = {} +display_settings['colorbar_label'] = 'Broken Vertices' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh_closed.faces +mesh_data['title'] = 'Mesh Close' +intensity_data = {} +intensity_data['values'] = broken_vertices_mesh_closed +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + + + +vertices = open_mesh.vertices +# center the vertices +vertices = vertices - np.mean(vertices, axis=0) +vertices_translate = np.copy(vertices) +# rotate the vertices +vertices_translate = np.dot(rot_x, vertices_translate.T).T +vertices_translate = np.dot(rot_z, vertices_translate.T).T +display_settings = {} +display_settings['colorbar_label'] = 'Broken Vertices' +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = open_mesh.faces +mesh_data['title'] = 'Mesh Close' +intensity_data = {} +intensity_data['values'] = broken_vertices_open_mesh +intensity_data["mode"] = "vertex" +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() diff --git a/examples/example_transfo_mesh.py b/examples/example_transfo_mesh.py new file mode 100644 index 00000000..2dec5bb2 --- /dev/null +++ b/examples/example_transfo_mesh.py @@ -0,0 +1,63 @@ +import slam.io as sio +import slam.differential_geometry as sdg +import numpy as np +from trimesh import transformations +mesh_file = "../examples/data/example_mesh.gii" + +mesh = sio.load_mesh(mesh_file) + +vertices = mesh.vertices + +theta = np.pi / 2 +rot_x = np.array([[1, 0, 0], + [0, np.cos(theta), -np.sin(theta)], + [0, np.sin(theta), np.cos(theta)]]) + + + +############################################################################# +# VISUALIZATION USING INTERNAL TOOLS +############################################################################# +import slam.plot as splt + +# Plot Original Mesh +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii Without Transformation' + +intensity_data = None +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + +mesh.apply_transform(mesh.principal_inertia_transform) + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = mesh.vertices +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii PCA Transformation' +intensity_data = None +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() + +vertices_translate = np.dot(rot_x, mesh.vertices.T).T + +display_settings = {} +mesh_data = {} +mesh_data['vertices'] = vertices_translate +mesh_data['faces'] = mesh.faces +mesh_data['title'] = 'example_mesh.gii With PCA and rotation Transformation' +intensity_data = None +Fig = splt.mes3d_projection( + mesh_data=mesh_data, + intensity_data=intensity_data, + display_settings=display_settings) +Fig.show() \ No newline at end of file