diff --git a/Cell_behavior_initial_steps/.gitkeep b/Cell_behavior_initial_steps/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Cell_behavior_initial_steps/Gts_selection.py b/Cell_behavior_initial_steps/Gts_selection.py new file mode 100644 index 0000000000000000000000000000000000000000..00c55c92c7b96a1f61217e212d59fcbd03dfe3d9 --- /dev/null +++ b/Cell_behavior_initial_steps/Gts_selection.py @@ -0,0 +1,53 @@ +#Gst generator,it is possible to choose a type of texture for the cell couture. +import numpy as np +import pickle +import random +import matplotlib.pyplot as ptl +import copy +from matplotlib import pyplot as plt +import random +from scipy import ndimage +from bio2mslib.inout.inout import WriteData as WD +import os + +#Selection of desire treated surface, Gts +First_Pickle= False +square_grid=False +highs_grid=False +diagonal=False + +if First_Pickle== True: + #L is the matrix dimension + L =12 + Lx =np.linspace(0, L, 12) + Ly =np.linspace(0, L, 12) + #G is the ground, an empty matrix to add the desire surface + G= np.zeros((L,L)) + #Gts us the ground for treated surface + Gts = copy.deepcopy(G) + if square_grid==True: + # #Square grid + for i in range (1,len(Lx)-1): + for j in range(1,len(Ly)-1): + if ((i % 2) !=0) or ((j % 2) ==0): + Gts[i,j] = 0.5 + elif highs_grid==True: + for i in range (1,len(Lx)-1): + for j in range(1,len(Ly)-1): + if i==0 or j==0 or i==len(Lx)-1 or j==len(Ly)-1: + Gst[i,j] = 0.5 + elif i==1 or j==1 or i==len(Lx)-2 or j==len(Ly)-2: + Gts[i,j] = 0.7 + elif diagonal==True: + for i in range (1,len(Lx)-1): + for j in range (1,len(Ly)-1): + if (i == j): + Gts[i,j]=0.5 +else: + with open('Gts_Sample.cvs', 'rb') as csv_file: + Gts = pickle.load(csv_file) +#If complete surface SMAT wants to be open type 'Gts_Surface_T.cvs' + +im = plt.imshow(Gts, cmap="bone") +plt.show() + diff --git a/Cell_behavior_initial_steps/Multiple_cell_behavior.gif b/Cell_behavior_initial_steps/Multiple_cell_behavior.gif new file mode 100644 index 0000000000000000000000000000000000000000..dce25c22160722e3eafead518473c964ebc283bb Binary files /dev/null and b/Cell_behavior_initial_steps/Multiple_cell_behavior.gif differ diff --git a/Cell_behavior_initial_steps/Pluri_cell_prolif_migr.py b/Cell_behavior_initial_steps/Pluri_cell_prolif_migr.py new file mode 100644 index 0000000000000000000000000000000000000000..ce1c4b51759ad3baef042361128876d473a9bca1 --- /dev/null +++ b/Cell_behavior_initial_steps/Pluri_cell_prolif_migr.py @@ -0,0 +1,82 @@ +import numpy as np +import pickle +import random +import matplotlib.pyplot as ptl +import copy +from matplotlib import pyplot as plt +import random +from scipy import ndimage +from bio2mslib.inout.inout import WriteData as WD +import os +from Gts_selection import L +from bio2mslib.analysis.models import CellModels as DM +from matplotlib.pyplot import figure + +#Declaring saving paths for results +ls_images=[] +results_path = os.getcwd()+os.sep+"Pluri_cell" +path_simulation_gif =os.getcwd()+os.sep+"Pluri_cell" +path_simulation = results_path+os.sep+"prolif_migr" +if os.path.isdir(path_simulation) == False : + os.mkdir(path_simulation) + +#Reopening choosen surface +with open('Gts_sample.cvs', 'rb') as csv_file: + Gts = pickle.load(csv_file) + +#Gs is ground seeded, a copy of the choosen surface to seed the cells, +Gs = copy.deepcopy(Gts) + +#Milticelular seeding +for i in range (4,L-6): + for j in range (4,L-7): + if Gs[i,j]==1: + Gs[i,j]+=0.5 + else: + Gs[i,j]=1.5 + +#images of the cell in the surface +couture= plt.imshow(Gs, cmap="bone") +plt.title("Gts, Inital seeding", + size=20) +plt.show() + + +#Variable deffinition for PDE proliferation & migration model +Cd = 1*10**-5 #Cell density +NO2 = 10**2 #nutrient concentration +Cdmax = 10**7 #maximum cell density +Dm = 0.001 #Cell motility coefficient +CRgrw = 1 #rate of cell growth +CRNO2 =10**-8 #Consumption rate of nutrients +DNO2 = 2*10**-5 +dt = 1 #time step +time_lapse = 0.1 + +Gscopy = copy.deepcopy(Gs) +Laplace = ndimage.laplace(Gs) +#Migration +iter = 0 +while iter<= 5: + for mi in range(1, L-1): + for mj in range(1, L-1): + x = random.randint(-1,1)#horizontal value for the movement of the cell + y = random.randint(-1,1)#vertival value for the movement of the cell + if Gs[mi,mj]==1.5 and (x != 0 or y!= 0) and ((mi+x)<L) and ((mj+y)< L): + Gs[mi+x,mj+y]= 1.5 + Gs[mi,mj]=0 + #Proliferation after migration + Gs[mi,mj] = Gscopy[mi,mj] + dt*Dm*Laplace[mi,mj]*(1-(Gscopy[mi,mj]/Cdmax))+CRgrw*1*Gscopy[mi,mj]*(1-(Gscopy[mi,mj]/Cdmax)) + if Gs[mi,mj]>0 and Gs[mi,mj]!=1: + Gs[mi,mj]=1.5 + plt.title("Gts, Proliferation and migration", + size=20) + im2 = plt.imshow(Gs, cmap="bone") + plt.show() + name = 'Single_cell_migr_prolif'+str(iter)+'.png' + plt.imsave(os.path.join(path_simulation, name), Gs, cmap="bone") + filename = name + ls_images.append(im2) + iter+=1 + +WD().create_gif_from_images(files_path=results_path+os.sep+"prolif_migr",results_path=path_simulation_gif,filename='Multiple_cell_behavior.gif', time_lapse= time_lapse, deleteOriginFiles=0) \ No newline at end of file diff --git a/Cell_behavior_initial_steps/Readme_1.md b/Cell_behavior_initial_steps/Readme_1.md new file mode 100644 index 0000000000000000000000000000000000000000..1cbbc727626a48f2bae4ff9adae9d909ecbf20d7 --- /dev/null +++ b/Cell_behavior_initial_steps/Readme_1.md @@ -0,0 +1,12 @@ +Readme file for Cell migration carpet + +Gts_selection is the first code that should be run, this allows the choosing of the surface where cells will be seeded. + +Uni_cell code intends to follow the cell movement living a trace after it. + +Single_cell_prolif_migr perfomes the behavior of one cell and saves the results in images and GIF. + +Pluri_cell_prolif_migr.py express the behavior of several cells and saves the result in images and GIF. + + +Pickle application for the code are foun in Follow_cell, this code to opens the last traces of the cell and continue from where it was taken. diff --git a/Cell_behavior_initial_steps/Uni_cell.py b/Cell_behavior_initial_steps/Uni_cell.py new file mode 100644 index 0000000000000000000000000000000000000000..9abe05633008e8e3edbd0d4e3b9addd9897cae4f --- /dev/null +++ b/Cell_behavior_initial_steps/Uni_cell.py @@ -0,0 +1,71 @@ +#Single cell migration giving a trace of the path it takes + +import numpy as np +import pickle +import random +import matplotlib.pyplot as ptl +import copy +from matplotlib import pyplot as plt +import random +from scipy import ndimage +from bio2mslib.inout.inout import WriteData as WD +import os + +#Empty matrix size declaration +lengthx = 12 +lengthy = 12 +G= np.zeros((lengthx,lengthy)) +ST = copy.deepcopy(G) + + +#Loop to add the \ surface +for i in range (0,12): + for j in range (0,12): + if (i == j): + ST[i,j]=0.5 + +#Pickle of the obtained matrix +with open('Cell_grid.pkl', 'wb') as csv_file: + pickle.dump(ST,csv_file) + +with open('Cell_grid.pkl', 'rb') as csv_file: + data_saved = pickle.load(csv_file) +Z = copy.deepcopy(ST) + +im2 = plt.imshow(Z, cmap="copper_r") +plt.show() + +#incertion of a single cell to track its movement based on the simpspn model +uni_cell = Z[(5,4)] +Z[(5,4)] = 1 +iter = 1 +itermax = 3 +im2 = plt.imshow(Z, cmap="copper_r") +plt.show() +while iter<= itermax: + for i in range(0,12): + for j in range(0,12): + # if Zcopy[im,jm]>= 1: + # Zcopyinitial = copy.deepcopy(Zcopy[im,jm]) + + h = random.randint(-1,1) #horizontal value for the movement of the cell + v = random.randint(-1,1) #vertival value for the movement of the cell + if Z[i,j]==1 and (h != 0 or v!= 0): + Z[i,j]= 0.7 + Z[h + i, v + j]= 1 + + + #Print the image to locate the cell each iteration. + #Saving the file of pickle + im2 = plt.imshow(Z, cmap="copper_r") + plt.show() + with open('Cell_migration_'+str(iter)+'.pkl', 'wb') as csv_file: + pickle.dump(Z,csv_file) + iter +=1 + + + + + + + diff --git a/Cell_behavior_initial_steps/single_cell_behavior_SMAT.gif b/Cell_behavior_initial_steps/single_cell_behavior_SMAT.gif new file mode 100644 index 0000000000000000000000000000000000000000..e76ac6dc2540414ca0668d47e8ae92aa9e0a50e4 Binary files /dev/null and b/Cell_behavior_initial_steps/single_cell_behavior_SMAT.gif differ diff --git a/Cell_behavior_initial_steps/single_cell_prolif_migr.py b/Cell_behavior_initial_steps/single_cell_prolif_migr.py new file mode 100644 index 0000000000000000000000000000000000000000..973957851d3fc4f662f215f9fdd583804e1e3cc7 --- /dev/null +++ b/Cell_behavior_initial_steps/single_cell_prolif_migr.py @@ -0,0 +1,78 @@ +import numpy as np +import pickle +import random +import matplotlib.pyplot as ptl +import copy +from matplotlib import pyplot as plt +import random +from scipy import ndimage +from bio2mslib.inout.inout import WriteData as WD +import os +from Gts_selection import L +from bio2mslib.analysis.models import CellModels as DM +from matplotlib.pyplot import figure + +#Declaring saving paths for results +ls_images=[] +results_path = os.getcwd()+os.sep+"Single_cell" +path_simulation_gif =os.getcwd()+os.sep+"Single_cell" +path_simulation = results_path+os.sep+"prolif_migr" +if os.path.isdir(path_simulation) == False : + os.mkdir(path_simulation) + +#Reopening choosen surface +with open('Gts_Sample.cvs', 'rb') as csv_file: + Gts = pickle.load(csv_file) + +#Gs is ground seeded, a copy of the choosen surface to seed the cells, +Gs = copy.deepcopy(Gts) + +#uni_cell is the seeding of a single cell inside the treated surface. +uni_cell = Gs[(8,8)] +Gs[(8,8)] = 1.5 +plt.title("Gts, Inital seeding", + size=20) +#images of the cell in the surface +couture= plt.imshow(Gs, cmap="bone") +plt.show() + +#Variable deffinition for PDE proliferation & migration model +Cd = 1*10**-5 #Cell density +NO2 = 10**2 #nutrient concentration +Cdmax = 10**7 #maximum cell density +Dm = 0.001 #Cell motility coefficient +CRgrw = 1 #rate of cell growth +CRNO2 =10**-8 #Consumption rate of nutrients +DNO2 = 2*10**-5 +dt = 1 #time step +time_lapse = 0.1 + +Gscopy = copy.deepcopy(Gs) +Laplace = ndimage.laplace(Gs) +#Migration +iter = 1 +while iter<= 5: + for mi in range(1, L-1): + for mj in range(1, L-1): + x = random.randint(-1,1)#horizontal value for the movement of the cell + y = random.randint(-1,1)#vertival value for the movement of the cell + if Gs[mi,mj]==1.5 and (x != 0 or y!= 0) and ((mi+x)<L) and ((mj+y)< L): + Gs[mi+x,mj+y]= 1.5 + Gs[mi,mj]+=0 + #Proliferation after migration + Gs[mi,mj] = Gscopy[mi,mj] + dt*Dm*Laplace[mi,mj]*(1-(Gscopy[mi,mj]/Cdmax))+CRgrw*1*Gscopy[mi,mj]*(1-(Gscopy[mi,mj]/Cdmax)) + if Gs[mi,mj]>0 and Gs[mi,mj]!=1 : + Gs[mi,mj]=1.5 + plt.title('Cell migration & proliferation '+str(iter), + size=20) + im2 = plt.imshow(Gs, cmap="bone", norm = None) + plt.show() + name = 'Single_cell_SMAT_sample'+str(iter)+'.png' + plt.imsave(os.path.join(path_simulation, name), Gs, cmap="bone") + filename = name + ls_images.append(filename) + iter+=1 + +WD().create_gif_from_images(files_path=results_path+os.sep+"prolif_migr",results_path=path_simulation_gif,filename='Cell_behavior_SMAT.gif', time_lapse= time_lapse, deleteOriginFiles=0) + + diff --git a/Data_array.xlsx b/Data_array.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..09f0752a1a964a45198394f531a35c5f8d486dfe Binary files /dev/null and b/Data_array.xlsx differ diff --git a/Gaus_surface.py b/Gaus_surface.py new file mode 100644 index 0000000000000000000000000000000000000000..3528e726e075a7eb528b6f9faed4e60a08f991ec --- /dev/null +++ b/Gaus_surface.py @@ -0,0 +1,42 @@ +#Code to arrange coordinates and values to create the surface for a posterior cell seeding. +import numpy as np +from Plotting_by_distance import data_t, L +import pickle + +#Initial matrix filled with 0 with the dimensions of Surface +E = np.zeros((414,545)) +#Choose False if its the first time running the code +Existing_surface=False + + +#Open the already existing surface +if Existing_surface==True: + with open('Gts_Surface_T.cvs', 'rb') as csv_file: + Gts = pickle.load(csv_file) +else: + Gts= E +#List with the discrete values for each coordinate in the plane +coord_value = (data_t[:,2]) + +#Iteration start +iter=1 +#Second iteration +fois=1 +#Loop to add by row the values of each coordinate +while fois < 411: + fois+=1 + #Definition of ranges for the values of 0 and 1 of the coordinates + min = 545*fois + max = 545*(fois+1) + #Part of the coordinate value list that will be introduced in the corresponding row + W= coord_value[min:max] + #r is the row number + r = 413-fois + for i in range(r-1,r): + for j in range(545): + #Adding the values of the list to each coordinate + Gts[i,j]= W[j] + #pickle the information entered in the matrix + with open('Gts_Surface_T.cvs', 'wb') as cvs_file: + pickle.dump(Gts,cvs_file) + diff --git a/Gaus_surface_3.py b/Gaus_surface_3.py new file mode 100644 index 0000000000000000000000000000000000000000..320f14631d3ca4d7304b51bfd5f435dce41111c3 --- /dev/null +++ b/Gaus_surface_3.py @@ -0,0 +1,43 @@ +#Code to arrange coordinates and values to create the surface for a posterior cell seeding. +#This code gices 3 different heights on the surface frol -1 to 1. +import numpy as np +from Plotting_3_levels import data_3, L +import pickle + +#Initial matrix filled with 0 with the dimensions of Surface +E = np.zeros((414,545)) +#Choose False if its the first time running the code +Existing_surface=False + + +#Open the already existing surface +if Existing_surface==True: + with open('Gts_Surface_multi_level.cvs', 'rb') as csv_file: + Gts = pickle.load(csv_file) +else: + Gts= E +#List with the discrete values for each coordinate in the plane +coord_value = (data_3[:,2]) + +#Iteration start +iter=1 +#Second iteration +fois=1 +#Loop to add by row the values of each coordinate +while fois < 415: + fois+=1 + #Definition of ranges for the values of 0 and 1 of the coordinates + min = 545*fois + max = 545*(fois+1) + #Part of the coordinate value list that will be introduced in the corresponding row + W= coord_value[min:max] + #r is the row number + r = 415-fois + for i in range(r-1,r): + for j in range(545): + #Adding the values of the list to each coordinate + Gts[i,j]= W[j] + #pickle the information entered in the matrix + with open('Gts_Surface_multi_level.cvs', 'wb') as cvs_file: + pickle.dump(Gts,cvs_file) + diff --git a/Gausian_plane.ply b/Gausian_plane.ply new file mode 100644 index 0000000000000000000000000000000000000000..b82bb8ebfa80e4892ecc872ed276f4ef41b62cb8 Binary files /dev/null and b/Gausian_plane.ply differ diff --git a/Gts_Surface.cvs b/Gts_Surface.cvs new file mode 100644 index 0000000000000000000000000000000000000000..0c44dc74f205966385a21ff560e6d84c791b64e5 Binary files /dev/null and b/Gts_Surface.cvs differ diff --git a/Plotting.py b/Plotting.py new file mode 100644 index 0000000000000000000000000000000000000000..3bf5de9a661ccf98c0df467d483c4d3002b1d7eb --- /dev/null +++ b/Plotting.py @@ -0,0 +1,40 @@ +#This code will provide the calcultaion to obtain dicretead data, in order to have coordintes +#and the values inside them corresponding to their height. +import numpy as np +import open3d as o3d +import copy + +# Read .ply file, this file contains guassian filter for the surface saved +input_file = "tata_filtered.ply" +pcd = o3d.io.read_point_cloud(input_file) # Read the point cloud + +# Convert open3d format to numpy array, the format here is point cloud in numpy format +Pc = np.asarray(pcd.points) +# +Sf = copy.deepcopy(Pc) + +L = len(Pc) +iter = 1 +#M is the media of surface rugossity, values under it will be 0, over this 1 +M = 3.17661 +while iter<= L: + for i in range (0,L): + for j in range (2, 3): + if Pc[i,j]> M: + Sf[i,j]=1 + else: + Sf[i,j]=0 + iter+=1 +#Treatment of coordinate to convert them from measurements to coordinates value for a 2D plane. +#For Y +Dt = copy.deepcopy(Sf) +for i in range (0,L): + for j in range (1,2): + Dt[i,j]= -int((Sf[i,j]+21.8168)/0.0052) +#For X +for i in range (0,L): + for j in range (0,1): + Dt[i,j]= -int((Sf[i,j]+8.445706367)/0.005214) + +data = np.flip(Dt, axis=0) +print(data) diff --git a/Plotting_3_levels.py b/Plotting_3_levels.py new file mode 100644 index 0000000000000000000000000000000000000000..b07d9be49d41f8abaaf16bcf2249aabe30a12066 --- /dev/null +++ b/Plotting_3_levels.py @@ -0,0 +1,44 @@ +import numpy as np +import open3d as o3d +import copy + +# Read .ply file +input_file = "tata_filtered.ply" +pcd = o3d.io.read_point_cloud(input_file) # Read the point cloud + +# Visualize the point cloud within open3d +# o3d.visualization.draw_geometries([pcd]) + +# Convert open3d format to numpy array +# Here, you have the point cloud in numpy format. +Pc = np.asarray(pcd.points) +#Sf for surface +Sf = copy.deepcopy(Pc) +#Legnth of Points cloud Pc +L = len(Pc) +iter = 1 +#Limits that will define the division between the 3 levels +M1 = 3.16287333 +M2= 3.18335667 +#Loop to arrange the values to their corresponding height from -1 to 1 +while iter<= L: + for i in range (0,L): + for j in range (2, 3): + if Pc[i,j]<=M1: + Sf[i,j]=-1 + elif Pc[i,j]<=M2: + Sf[i,j]=0 + else: + Sf[i,j]=1 + iter+=1 +#Treatment of coordinate to convert them from measurements to coordinates value for a 2D plane. +Dt = copy.deepcopy(Sf) +for i in range (0,L): + for j in range (1,2): + Dt[i,j]= -int((Sf[i,j]+21.8168)/0.0052) +#For X +for i in range (0,L): + for j in range (0,1): + Dt[i,j]= -int((Sf[i,j]+8.445706367)/0.005214) +#Order the array of values Y axis from mayor to minor. +data_3 = np.flip(Dt, axis=0) \ No newline at end of file diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..ace037e0be3c1284b326b4e49ba45e688be10608 --- /dev/null +++ b/Readme.md @@ -0,0 +1,29 @@ +Code to interpretate an stl file of a Alloy surface treated for biomedical intention to perform cell seeding. +The repertory is conformed by an initial stl file containing the analized surface, and 3 codes to obtained a 2D surface. + + +1. Run "stl2vtk.py" +This will show the studied surface, the entering file needs to be in stl format. +As a result a ply file will be obtained for further treatment. +In this code, several methods to study and find surface parameters are commented out. + +2. Run "Plotting.py" +The "tata_filtered.ply" is the input that will provide the arrays to create a 2D plane +Inside an array of the same size as the surface. +An array of 3 columns and n number of points will be obtained. +1 and 2nd columns correspond to coordinaes x and y. 3rd column is the value inside each coordinate. +This array is saved in the "data" variable. + +3. Run "Gaus_surface.py" +Array values will be arranged inside the matrix to plot the 2D plane from 'data' calculated in previously. +Firstly an empty Matrix with the same dimmension is created filled with 0. +The main task of the code is to correctly arrange each coordinate value into its corresponding location +in the Gts matrix. +Values are added from the bottom to the top by pickling each time a row is added. +This provides a file containing the surface heights fom 1 to 0. + +4. Additional: "Show_code.py" +This code show the final surface obtained in a colored plot. +It also allows to obtain a small sample if needed to perfom fast test with cell seeding called +"Gts_sample.cvs" + diff --git a/Results/.gitkeep b/Results/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Results/Bone.png b/Results/Bone.png new file mode 100644 index 0000000000000000000000000000000000000000..c93f2629a4532fb38447d688815ebd0a95b5ec0d Binary files /dev/null and b/Results/Bone.png differ diff --git a/Results/Bone1.png b/Results/Bone1.png new file mode 100644 index 0000000000000000000000000000000000000000..05e48ebe73f105f3560722b10c81c551d1cdbfd3 Binary files /dev/null and b/Results/Bone1.png differ diff --git a/Results/Cell_behavior_SMAT.gif b/Results/Cell_behavior_SMAT.gif new file mode 100644 index 0000000000000000000000000000000000000000..c18c4b0931cefb4106cb5455fb027bb8f644f662 Binary files /dev/null and b/Results/Cell_behavior_SMAT.gif differ diff --git a/Results/Gts_Surface.cvs b/Results/Gts_Surface.cvs new file mode 100644 index 0000000000000000000000000000000000000000..0c44dc74f205966385a21ff560e6d84c791b64e5 Binary files /dev/null and b/Results/Gts_Surface.cvs differ diff --git a/Results/Gts_Surface_0.cvs b/Results/Gts_Surface_0.cvs new file mode 100644 index 0000000000000000000000000000000000000000..b8cf443bb892c440df3d30acaadf5b423f128ae6 Binary files /dev/null and b/Results/Gts_Surface_0.cvs differ diff --git a/Results/Gts_Surface_multi_level.cvs b/Results/Gts_Surface_multi_level.cvs new file mode 100644 index 0000000000000000000000000000000000000000..dc57fa8a63cfe7c7f890187b1dfff884c4e7658f Binary files /dev/null and b/Results/Gts_Surface_multi_level.cvs differ diff --git a/Results/SMAT_Gaus_Filter.png b/Results/SMAT_Gaus_Filter.png new file mode 100644 index 0000000000000000000000000000000000000000..de9c7c3a0e565ca8163c8279354a7cd8f7678526 Binary files /dev/null and b/Results/SMAT_Gaus_Filter.png differ diff --git a/Results/SMAT_metallic_plot.png b/Results/SMAT_metallic_plot.png new file mode 100644 index 0000000000000000000000000000000000000000..154c8aedf2ba47155a7beabb2b9393ae2ab92675 Binary files /dev/null and b/Results/SMAT_metallic_plot.png differ diff --git a/Results/Single_cell_SMAT_sample0.png b/Results/Single_cell_SMAT_sample0.png new file mode 100644 index 0000000000000000000000000000000000000000..cc4dc404c026dc4935effe501851f35f6c10464c Binary files /dev/null and b/Results/Single_cell_SMAT_sample0.png differ diff --git a/Results/Single_cell_SMAT_sample1.png b/Results/Single_cell_SMAT_sample1.png new file mode 100644 index 0000000000000000000000000000000000000000..d497d0d2b578e8afdb2743a9aa5d1b0388df824e Binary files /dev/null and b/Results/Single_cell_SMAT_sample1.png differ diff --git a/Results/from_stl.ply b/Results/from_stl.ply new file mode 100644 index 0000000000000000000000000000000000000000..b82bb8ebfa80e4892ecc872ed276f4ef41b62cb8 Binary files /dev/null and b/Results/from_stl.ply differ diff --git a/Show_code.py b/Show_code.py new file mode 100644 index 0000000000000000000000000000000000000000..ae63b7c4aa7147e1335c91e9e6d1cf85451f1479 --- /dev/null +++ b/Show_code.py @@ -0,0 +1,22 @@ +import pickle +import matplotlib.pyplot as plt +import os + + +with open('Gts_Surface_T.cvs', 'rb') as csv_file: + Gts = pickle.load(csv_file) + +Plot = plt.imshow(Gts, cmap="bone", norm = None, aspect ='equal' ) +plt.show() + + +#Section to create an array corresponding to a section of the full matrix +L= 15 +Sample= Gts[0:L, 0:L] + +with open('Gts_Sample.cvs', 'wb') as cvs_file: + pickle.dump(Sample,cvs_file) + +#Showing the sample in a plot +Plot_sample = plt.imshow(Sample, cmap="bone", norm = None, aspect ='equal' ) +plt.show() \ No newline at end of file diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/data/SMAT.stl b/data/SMAT.stl new file mode 100644 index 0000000000000000000000000000000000000000..92419ebcef69d4f384cc6da27be7dcf1a533ee64 Binary files /dev/null and b/data/SMAT.stl differ diff --git a/from_stl.ply b/from_stl.ply new file mode 100644 index 0000000000000000000000000000000000000000..b82bb8ebfa80e4892ecc872ed276f4ef41b62cb8 Binary files /dev/null and b/from_stl.ply differ diff --git a/stl2vtk.py b/stl2vtk.py new file mode 100644 index 0000000000000000000000000000000000000000..863eb0647beb5429d22da71908fdb59b1e742ce1 --- /dev/null +++ b/stl2vtk.py @@ -0,0 +1,86 @@ +# Copyright University of Lorraine - LEM3 +# Contributor(s) : +# Adrien Baldit +# Contact: adrien.baldit@univ-lorraine.fr +# +# This script is a computer program whose purpose is to produce +# biomechanical and bioengineering data processing. +# +# This script is governed under French law and abiding by the rules +# of distribution of free script. You can use, modify and/ or +# redistribute the script under the terms of honor +# +# As a counterpart to the access to the source code and rights to copy, +# modify and redistribute granted by the honor, users are provided only +# with a limited warranty and the script's author, the holder of the +# economic rights, and the successive licensors have only limited +# liability. +# +# In this respect, the user's attention is drawn to the risks associated +# with loading, using, modifying and/or developing or reproducing the +# script by the user in light of its specific status of free software, +# that may mean that it is complicated to manipulate, and that also +# therefore means that it is reserved for developers and experienced +# professionals having in-depth computer knowledge. Users are therefore +# encouraged to load and test the script's suitability as regards their +# requirements in conditions enabling the security of their systems and/or +# data to be ensured and, more generally, to use and operate it in the +# same conditions as regards security. +# +# The fact that you are presently reading this means that you have +# had knowledge of the rules and accepted them. + +#!/usr/bin/python +# -*- coding:utf8 -*- + +# pyvista library import +import pyvista as pv +# operating system import +import os +from scipy import misc +from mpl_toolkits import mplot3d +from matplotlib import pyplot +from matplotlib import pyplot as plt +import pyvista +# ~ from bio2mslib.inout.inout import Read_data as RD +cell_center = False +file_parameters = False +elevation = False +# intercative plotting +# ~ pl.ion() + +# Test folder list +test_list = ["SMAT",\ + ] + + +# file path +file_path = os.getcwd()+os.sep+"data" + +# file path +result_path = os.getcwd()+os.sep+"results" + +if os.path.isdir(result_path) == False : + os.mkdir(result_path) + + +name = 'Surface' +# post processing loop +for i,m in enumerate(test_list) : + + # TRA filename + filename = m + ".stl" + + tata = pv.read(file_path+os.sep+filename) + + +#This command provides an array, we decide the parameters +tata['value'] = tata.points[:,1]#Value give us the coordninates of eqch point + +# tata.plot_boundaries(line_width = 5) +tata_filtered= tata.plot_curvature(curv_type='gaussian', smooth_shading=True, + clim=[0, 1]) + +tata.save('tata_filtered.ply') + + diff --git a/stl_atributes.py b/stl_atributes.py new file mode 100644 index 0000000000000000000000000000000000000000..6f1d4e202814d363f33846cef3f3c3f1ecffeb20 --- /dev/null +++ b/stl_atributes.py @@ -0,0 +1,109 @@ +#Pyvista information from stl file +import pyvista as pv +# operating system import +import os +from scipy import misc +from mpl_toolkits import mplot3d +from matplotlib import pyplot as plt +import pyvista + +test_list = ["SMAT",\ + ] +# file path +file_path = os.getcwd()+os.sep+"data" +# file path +result_path = os.getcwd()+os.sep+"results" +if os.path.isdir(result_path) == False : + os.mkdir(result_path) +name = 'Surface' +# post processing loop +for i,m in enumerate(test_list) : + # TRA filename + filename = m + ".stl" + tata = pv.read(file_path+os.sep+filename) + +#Printing and saving stl parameters + cells = tata.n_cells + points = tata.n_points + bounds = tata.bounds + arrays = tata.n_arrays + + print(tata.n_cells) + print(tata.n_points) + print(tata.bounds) + print(tata.n_arrays) + print(tata.area) + +#show surface with metallic attributes for a clearer view and roughness signaling +tata.plot(cpos='xy', cmap='plasma', pbr=True, metallic=1.0, roughness=0.3, + zoom=0.7, text='SMATed surface',return_cpos=False, hidden_line_removal= True, anti_aliasing=True) + +#Filter to obtain curvature values of the surface for further treatment into values of 0 and 1. +tata_filtered= tata.plot_curvature(curv_type='gaussian', smooth_shading=True, + clim=[0, 1]) +Gaus = tata.get_array('Gaussian Curvature') +print(Gaus) + + +#Locate the arrays inside the PolyData, this provides the arrays containing values of scalars, normals +#faces and points. +print(tata.array_names) +#printing the array founded and saving it as a tuple inside a callable variable +choc = tata.get_array('Normals') +tata.save('tata.vtk') + +#Data range, min,max given +tata_r = tata.get_data_range() + +#Edges showing in red +tata.plot_boundaries(line_width=5) +choc= choc.plot_curvature(curv_type='gaussian', smooth_shading=True, + clim=[0, 1]) + +#Make a plane figure with edges planed, erased the edges due to the high aglomeration +#In this model we can see how the values change along the plane +projected = tata.project_points_to_plane() + projected.plot(show_edges=False, line_width=0.3) + +#Code to show the mesh that composes the figure + mesh = tata + mesh.point_data.clear() + centers = mesh.cell_centers() + pl = pyvista.Plotter() + actor = pl.add_mesh(mesh, show_edges=False) + actor = pl.add_points(centers, render_points_as_spheres=True, + color='red', point_size=10) + pl.show() + +#Code to show the elevation in the Z plane + tata_elv = tata.elevation() + print(tata_elv) + tata_elv.plot(smooth_shading=True) +# Calculate de distance of entitites from a plane in the middle, doesnt stays in the middle the plane +plane = pv.Plane() +_ = tata.compute_implicit_distance(plane, inplace=True) +dist = tata['implicit_distance'] +type(dist) +pl = pv.Plotter() +_ = pl.add_mesh(tata, scalars='implicit_distance', cmap='bwr') +_ = pl.add_mesh(plane, color='w', style='wireframe') +pl.show() +merged = tata.merge(plane) +merged.plot(style='wireframe',color='tan') +ow = tata.overwrite(plane) +merged.plot(style='wireframe',color='tan') + + + +#Interpolation of our data in a mesh +pdata = pyvista.PolyData(tata) +plane = pyvista.Plane() +plane.clear_data() +plane = plane.interpolate(pdata, sharpness=3) +pl = pyvista.Plotter() +_ = pl.add_mesh(pdata, render_points_as_spheres=True, point_size=50) +_ = pl.add_mesh(plane, style='wireframe', line_width=5) +pl.show() + +# Normal ploting +tata.plot_normals(mag=0.1,faces=False, show_edges=False) \ No newline at end of file diff --git a/tata.vtk b/tata.vtk new file mode 100644 index 0000000000000000000000000000000000000000..4b64ef1d8c18a7ef9afa1cef3ff5e471e523f231 Binary files /dev/null and b/tata.vtk differ diff --git a/tata_filtered.ply b/tata_filtered.ply new file mode 100644 index 0000000000000000000000000000000000000000..b82bb8ebfa80e4892ecc872ed276f4ef41b62cb8 Binary files /dev/null and b/tata_filtered.ply differ