diff --git a/examples/example_curvature.py b/examples/example_curvature.py index 6a235af..0b090e3 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 02077f4..3ee4fdc 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_texture.py b/examples/example_texture.py index 4d07700..34d8ed3 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 1f3052c..37d4869 100644 --- a/examples/example_topology.py +++ b/examples/example_topology.py @@ -92,13 +92,81 @@ 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 +# 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 @@ -222,9 +290,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 47377b5..8e84323 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/examples/test.gii b/examples/test.gii deleted file mode 100644 index 841a02e..0000000 --- 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 8c28503..1c7ccd0 100755 --- a/slam/plot.py +++ b/slam/plot.py @@ -143,4 +143,4 @@ def mes3d_projection(mesh_data, intensity_data=None, display_settings=None): }, ) - return fig + return fig \ No newline at end of file