Skip to content
Snippets Groups Projects
Commit 5d6f74c1 authored by Boman Romain's avatar Boman Romain
Browse files

put mesh files in folder

parent 52fb095a
No related branches found
No related tags found
No related merge requests found
unsaved/
workspace/
meshes/
gmsh/
*.msh
__pycache__/
.vscode/
......
......@@ -15,18 +15,20 @@ def parms(d={}):
p = {}
# Geomagic/MeshLab input files
p['mandible'] = 'Dolicorhynchops_coarse.ply' # mandible mesh (.ply/.geo/.msh)
p['teeth'] = 'teeth.off' # one or several vertices (.ply/.off)
p['LTMJ'] = 'LTMJ.off' # left temporomandibular joint - 1 vertex (.ply/.off)
p['RTMJ'] = 'RTMJ.off' # right temporomandibular joint - 1 vertex (.ply/.off)
p['muscles'] = {
'Lmuscle.ply': { 'force': 100., 'focalpt':'LmuscleF.off'},
'Rmuscle.off': { 'force': 100., 'focalpt':'RmuscleF.off'}
}
path = 'dolicorhynchops/10k'
p['mandible'] = f'{path}/mandible.ply' # mandible mesh (.ply/.geo/.msh)
p['teeth'] = f'{path}/teeth.off' # one or several vertices (.ply/.off)
p['LTMJ'] = f'{path}/LTMJ.off' # left temporomandibular joint - 1 vertex (.ply/.off)
p['RTMJ'] = f'{path}/RTMJ.off' # right temporomandibular joint - 1 vertex (.ply/.off)
p['muscles'] = [
{ 'file': f'{path}/Lmuscle.ply', 'force': 100., 'focalpt':f'{path}/LmuscleF.off'},
{ 'file': f'{path}/Rmuscle.off', 'force': 100., 'focalpt':f'{path}/RmuscleF.off'}
]
# material properties
p['density'] = 1.850e-9 # [T/mm³] - bone: 1.850 kg/l
p['Young'] = 17000.0 # [MPa] elastic modulus - bone: 17-20 GPa
p['Young'] = 17000. # [MPa] elastic modulus - bone: 17-20 GPa
p['Poisson'] = 0.3 # [-] Poisson's ratio
# numerical parameters
......@@ -45,8 +47,7 @@ def getMetafor(p={}):
geometry = domain.getGeometry()
geometry.setDim3D()
# load main mandible mesh (volume or surface - it will be meshed in 3D)
import_mesh(domain, p['mandible'])
# define groups
......@@ -58,36 +59,31 @@ def getMetafor(p={}):
print("the whole mesh has %d nodes" % groups['all'].getNumberOfMeshPoints())
# external surface of the mesh
# extract external surface of the mesh => groups['surf']
# nods_no: tags of the nodes
# nods_pos: coordinates of these nodes
groups['surf'] = groupset.add(Group(groupset.getLargestNo()+1))
groups['surf'].addMeshPointsFromObject(groups['all'], BoundarySelector())
nods_no, nods_pos = extract_nodes_from_group(groups['surf'])
# loads all surface meshes & vertices
# load other surface meshes => groups['LTMJ'], ...
for meshname in ['LTMJ', 'RTMJ', 'teeth']:
create_group(p[meshname], nods_no, nods_pos, domain, groups, meshname)
# ...left/right temporomandibular joint => groups['LTMJ'], ...
create_group('LTMJ.off', nods_no, nods_pos, domain, groups)
create_group('RTMJ.off', nods_no, nods_pos, domain, groups)
# ...teeth => groups['teeth']
create_group(p['teeth'], nods_no, nods_pos, domain, groups)
# ...muscle groups
# load muscle groups
mgroups = {} # stores muscle group data and loads
for name, gr in p['muscles'].items():
for muscle in p['muscles']:
# load focal point
fullpath = os.path.join(os.path.dirname(__file__), gr['focalpt'])
fullpath = os.path.join(os.path.dirname(__file__), muscle['focalpt'])
focalnodes, _ = loadbone.load_msh(fullpath)
# load surface mesh => groups[name]
nodes, tris, ntags = create_group(name, nods_no, nods_pos, domain, groups)
# load surface mesh => groups[name (from filename)]
name, nodes, tris, ntags = \
create_group(muscle['file'], nods_no, nods_pos, domain, groups)
# create loads on the surface
shortname = os.path.splitext(os.path.basename(name))[0]
loads = loadbone.create_uniform_loads(nodes, tris, \
total_force=gr['force'], target=focalnodes[0])
total_force=muscle['force'], target=focalnodes[0])
# store data in a structure
mgroups[shortname] = MuscleGroup(nodes, tris, ntags, loads)
mgroups[name] = MuscleGroup(nodes, tris, ntags, loads)
# ------------------------------------------------------------------
......@@ -171,7 +167,7 @@ def import_mesh(domain, filename):
- .ply: a .geo is written in the workspace and loaded into gmsh
"""
# import gmsh file (accept .geo, .msh or .ply)
mandible_gmsh=filename
mandible_gmsh = filename
# make the path absolute
if not os.path.isabs(mandible_gmsh):
mandible_gmsh = os.path.join(os.path.dirname(__file__), mandible_gmsh)
......@@ -182,7 +178,7 @@ def import_mesh(domain, filename):
noext,ext = os.path.splitext(mandible_gmsh)
if ext=='.ply':
plyfile = mandible_gmsh
# creates 2 workspace files
# create 2 workspace files
basename = os.path.join(os.getcwd(), os.path.basename(noext))
mshfile = f"{basename}.msh"
geofile = f"{basename}.geo"
......@@ -223,26 +219,39 @@ def extract_nodes_from_group(group):
return nods_no, nods_pos
def create_group(off_file, all_no, all_coords, domain, groups):
"""loads the mesh file "off_file" and identify vertices among vertices
def create_group(mesh_file, all_no, all_coords, domain, groups, gname=None):
"""loads the mesh file "mesh_file" and identify vertices among vertices
stored in all_coords.
Then, the routine creates a group named "off_file" (without ".off")
Then, the routine creates a group named "gname" (built from mesh_file if None)
"""
fullpath = os.path.join(os.path.dirname(__file__), off_file)
# load mesh file
fullpath = os.path.join(os.path.dirname(__file__), mesh_file)
nodes, tris = loadbone.load_msh(fullpath)
# identify nodes of the mesh among the given vertices of the main mesh
ntags = loadbone.identify_nodes(nodes, all_no, all_coords)
# create a metafor group
groupset = domain.getGeometry().getGroupSet()
name = os.path.splitext(off_file)[0]
groups[name] = groupset.add(Group(groupset.getLargestNo()+1))
if gname is None:
gname, _ = os.path.splitext(os.path.basename(mesh_file))
group = groupset.add(Group(groupset.getLargestNo()+1))
groups[gname] = group
# add all the identified vertices to the group
nodeset = domain.getGeometry().getMesh().getPointSet()
for tag in ntags:
groups[name].addMeshPoint(nodeset(tag))
print(f'group #{groups[name].getNo()} ({name}) ' \
f'created from {off_file} ({groups[name].getNumberOfMeshPoints()} nodes)')
return nodes, tris, ntags
group.addMeshPoint(nodeset(tag))
print(f'group #{group.getNo()} ({gname}) ' \
f'created from {mesh_file} ({group.getNumberOfMeshPoints()} nodes)')
return gname, nodes, tris, ntags
class MuscleGroup:
"""convenient structure for storing muscle data and loads
"""
def __init__(self, nodes, tris, ntags, loads):
self.nodes = nodes
self.tris = tris
......
File moved
File moved
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment