Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ac2868b3 authored by CERUTTI Guillaume's avatar CERUTTI Guillaume
Browse files

udpate example notebook

parent 00319252
Branches
Tags
1 merge request!4NumPy warnings + verbosity updates
%% Cell type:markdown id: tags:
# Computing Geometrical Properties on a PropertyTopomesh
In CellComplex, cell tissues are represented as meshes (more exactly cellular complexes implemented as incidence graphs) in an object called **PropertyTopomesh**. This data structure contains the geometry and topology of the cells, and can also bear other properties defined on each of its elements (vertices, edges, faces or cells).
The CellComplex.PropertyTopomesh library comes with tools to automatically compute a whole range of geometrical properties on the tissue mesh (*compute_topomesh_property*) and to propagate properties between elements of different dimensions (*compute_topomesh_vertex_property_from_faces* for instance).
%% Cell type:code id: tags:
``` python
import numpy as np
import os
from cellcomplex.property_topomesh.analysis import compute_topomesh_property
from cellcomplex.property_topomesh.analysis import compute_topomesh_vertex_property_from_faces
from cellcomplex.property_topomesh.analysis import compute_topomesh_cell_property_from_faces
```
%% Cell type:markdown id: tags:
It is possible to construct a **PropertyTopomesh** from standard mesh file formats, such as PLY. Here an example of a meristematic L1 tissue saved as a PLY file, provided as an example in the *share/data* directory of the package, is loaded.
%% Cell type:code id: tags:
``` python
import cellcomplex.property_topomesh
dirname = os.path.abspath(cellcomplex.property_topomesh.__path__[0]+"/../../../share/data")
print(dirname)
filename = os.path.join(dirname,"p194-t4_L1_topomesh.ply")
from cellcomplex.property_topomesh.io import read_ply_property_topomesh
topomesh = read_ply_property_topomesh(filename,verbose=False)
topomesh = read_ply_property_topomesh(filename)
```
%% Cell type:markdown id: tags:
The tissue is a surfacic triangular mesh where triangles are linked to a labelled cell. Each label can be mapped to an independent color for visualization.
%% Cell type:code id: tags:
``` python
# Specific function for 3D visualization in notebooks
#from cellcomplex.property_topomesh.triangular_mesh import topomesh_to_triangular_mesh
#mesh,_ = topomesh_to_triangular_mesh(topomesh,3,coef=0.95)
#mesh._repr_vtk_()
%matplotlib notebook
import matplotlib.pyplot as plt
from cellcomplex.property_topomesh.utils.matplotlib_tools import mpl_draw_topomesh
figure = plt.figure(0)
figure.clf()
mpl_draw_topomesh(topomesh,figure,3,colormap='jet')
mpl_draw_topomesh(topomesh,figure,1,cell_edges=True,color='w')
figure.gca().axis('equal')
```
%% Cell type:code id: tags:
``` python
compute_topomesh_property?
```
%% Cell type:markdown id: tags:
Based on this initial mesh, we would like to compute the curvature of the surface. To do so, we will use the function *compute_topomesh_property* to compute the geometrical properties allowing to obtain this information.
The first property to compute is the **normal** of the faces (elements of degree = 2). Given the implementation as an incidence graph, the order of vertices for each face is not unambiguous, hence the orientation of faces is not contained in the surface. It is necessary to have a way of re-orienting consistently the normals. Here we choose the *orientation* mode that propagates the orientation infomration in a topologically accurate way on a connected surfacic mesh.
Next, we compute the **area** of all faces, and use it to compute the **normal** property on the vertices (elements of degree = 0). This is done by averaging the normals of faces neighboring each vertex using the function *compute_topomesh_vertex_property_from_faces*.
Once each vertex bears a consistent normal, it is possible to compute the **mean curvature** of the each face (actually the **3D curvature tensor** containing all the information on the principal curvatures, in particular mean, gaussian, min and max curvatures). This property can be propagated to the vertices using the same method as for the normals.
%% Cell type:code id: tags:
``` python
compute_topomesh_property(topomesh,'normal',2,normal_method='orientation')
compute_topomesh_property(topomesh,'area',2)
compute_topomesh_vertex_property_from_faces(topomesh,'normal',weighting='area',adjacency_sigma=1.2,neighborhood=3)
compute_topomesh_property(topomesh,'mean_curvature',2)
compute_topomesh_vertex_property_from_faces(topomesh,'mean_curvature',weighting='area',adjacency_sigma=1.2,neighborhood=3)
```
%% Cell type:markdown id: tags:
This numerical property can be visualized on the triangles of the mesh using the property on the vertices, creating a smooth interpolation of curvature values.
%% Cell type:code id: tags:
``` python
figure = plt.figure(1)
figure.clf()
mpl_draw_topomesh(topomesh,figure,2,property_name='mean_curvature',intensity_range=(-0.05,0.05),colormap='RdBu_r')
figure.gca().axis('equal')
```
%% Cell type:markdown id: tags:
Alternatively, the mean curvature could be propagated to the cells (elements of degree = 3) to have unique value for each cell of the tissue. This value can then be conveniently visualized on a representation of the mesh that specifically isolates the cells.
%% Cell type:code id: tags:
``` python
print(compute_topomesh_cell_property_from_faces.__doc__)
compute_topomesh_cell_property_from_faces(topomesh,'mean_curvature')
figure = plt.figure(2)
figure.clf()
mpl_draw_topomesh(topomesh,figure,3,property_name='mean_curvature',intensity_range=(-0.05,0.05),colormap='RdBu_r')
mpl_draw_topomesh(topomesh,figure,1,cell_edges=True,color='w')
figure.gca().axis('equal')
```
%% Cell type:markdown id: tags:
All the properties are stored inside the topomesh that can then be saved with only the desired properties in a standard PLY file.
%% Cell type:code id: tags:
``` python
save_filename = os.path.join(dirname,"p194-t4_L1_topomesh_curvature.ply")
from cellcomplex.property_topomesh.io import save_ply_property_topomesh
save_ply_property_topomesh(topomesh,save_filename,
properties_to_save=dict([(0,[]),(1,[]),(2,[]),(3,['mean_curvature'])]))
```
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment