Skip to content
Snippets Groups Projects

Update README.md

Merged encinass1u requested to merge Student into main
1 file
+ 162
0
Compare changes
  • Side-by-side
  • Inline
stl2vtk.py 0 → 100644
+ 162
0
# 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['value'] = tata.points[:,2]
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)
# 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')
Gaus = tata.get_array('Gaussian Curvature')
print(Gaus)
#Locate the arrays inside the PolyData
print(tata.array_names)
#printing the array founded and saving it as a tuple in a variable
choc = tata.get_array('Normals')
tata.save('tata.vtk')
# print(choc)
#Data range, min,max given
# tata_r = tata.get_data_range()
#Edges showing
# 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
# projected = tata.project_points_to_plane()
# projected.plot(show_edges=False, line_width=0.3)
if file_parameters==True:
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)
if cell_center==True:
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()
if elevation ==True:
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')
# aso= tata.get_array_association('Normals')
# print(aso)
#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
Loading