Commit 0f6e65af authored by Maxence Reberol's avatar Maxence Reberol
Browse files

Initial commit

parents
# Personal config
CMakeOptions.txt
# Build folders
build/
Linux64-gcc-dynamic-Release/
Linux64-gcc-dynamic-RelWithDebInfo/
Linux64-gcc-dynamic-Debug/
# Compilation info
compile_commands.json
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# warning
early prototype stage
# launcher
A small gmsh launcher
[Image](./figures/launcher.png)
Usage:
In this repository directory (pathes are not well managed yet):
python3 laucher.py /path/to/gmsh /path/to/directory/with/CAD_models_or_meshes
# Requirements
pip install --user dearpygui
xvfb-run (to run gmsh in background to take screenshots)
create a directory named "cache_png" in the current directory to store screenshots
#!/usr/bin/python3
import argparse
import os
import json
import subprocess
import glob
from dearpygui.core import *
from dearpygui.simple import *
# Global variables for easier code ...
model_files = []
last_selected = ""
last_figures = []
table_name = "CAD models and meshes"
def update_command(args):
cmd = args.gmsh
if get_value("-2"): cmd += " -2"
if get_value("-3"): cmd += " -3"
cmd += " -clscale " + str(get_value("-clscale"))
cmd += " -nt " + str(get_value("-nt"))
cmd += " -algo " + str(get_value("-algo"))
if last_selected != "":
cmd += " " + last_selected
return cmd
def update_var(sender, data):
my_var = get_value(sender)
def launch_command(sender, data):
cmd = get_value("cmd_text")
if get_value("Compile before"):
directory = cmd.split(" ")[0]
directory = os.path.dirname(directory)
cmd_compile = "ninja -C " + directory
print(cmd_compile)
subprocess.call(cmd_compile,shell=True)
if get_value("Close existing"):
cmd_kill = "killall -9 gmsh"
print(cmd_kill)
subprocess.call(cmd_kill, shell=True)
print(cmd)
subprocess.Popen(cmd,shell=True)
def kill_command(sender, data):
cmd_kill = "killall -9 gmsh"
print(cmd_kill)
subprocess.call(cmd_kill, shell=True)
def update_figures(path):
if not path or not os.path.isfile(path):
return
global last_figures
name = os.path.splitext(os.path.basename(path))[0]
shots = glob.glob("cache_png/" + name + "*.png")
if len(shots) == 0:
cmd = "xvfb-run python3 screenshot_with_gmsh.py"
cmd += " " + path
cmd += " cache_png/" + name
subprocess.call(cmd,shell=True)
shots = glob.glob("cache_png/" + name + "*.png")
if len(shots) > 0:
last_figures = shots
def update_model_selection(sender, data):
global last_selected
sl = get_table_selections(table_name)
k = []
for s in sl:
name = model_files[s[0]]
if name != last_selected:
last_selected = name
k = s
break
if not k and len(sl) == 1:
k = sl[0]
for s in sl:
if s == k:
set_table_selection(table_name,s[0],s[1],True)
else:
set_table_selection(table_name,s[0],s[1],False)
update_figures(last_selected)
def update_table(sender,data):
print("a")
def table_with_files(args):
# add_window("Data",x_pos=0,y_pos=300, autosize=True)
add_text(str(len(model_files)) + " files")
add_input_text("Filter")
add_same_line(spacing=10)
add_button("Apply",callback=update_table)
add_table(table_name, ["Name"], height=200, callback=update_model_selection)
for f in model_files:
add_row(table_name, [f])
def setup_GUI(args):
H = 800
add_window("Gmsh launcher",width=300,height=H,x_pos=0,y_pos=0,autosize=True)
add_text("Executable: " + str(args.gmsh))
add_dummy(height=10)
add_checkbox("-2",default_value=False,callback=update_var)
add_same_line(spacing=10)
add_checkbox("-3",default_value=False,callback=update_var)
add_slider_float("-clscale", default_value=1., min_value=0.01, max_value=3, format="%.3f",callback=update_var)
set_item_width("-clscale",100)
add_slider_int("-nt",default_value=1, min_value=1, max_value=8,callback=update_var)
set_item_width("-nt",100)
add_input_text("-algo", default_value="quadqs", width=100)
# for opt in config["options"]:
# if len(opt) == 1:
# add_checkbox(opt[0])
# elif len(opt) == 2:
# add_input_text(opt[0], default_value=opt[1])
# set_item_width(opt[0],80)
add_dummy(height=10)
add_text("cmd_text")
set_value("cmd_text",update_command(args))
add_checkbox("Compile before",default_value=True,callback=update_var)
add_same_line(spacing=10)
add_checkbox("Close existing",default_value=True,callback=update_var)
add_button("Run",callback=launch_command)
add_same_line(spacing=10)
add_button("Kill",callback=kill_command)
add_separator()
table_with_files(args)
add_separator()
add_text("Figures:")
add_drawing("figures_png", width=300,height=300)
end()
if __name__=="__main__":
parser = argparse.ArgumentParser(description='Launcher')
parser.add_argument('gmsh', type=str, help='Gmsh executable path')
parser.add_argument('data', nargs="+", type=str, help='Directories with the data (CAD models, meshes)')
args = parser.parse_args()
assert os.path.isfile(args.gmsh)
print("Parse input directories ...", args.data)
for folder in args.data:
model_files += glob.glob(folder + '/**/*.step', recursive=True) \
+ glob.glob(folder + '/**/*.stp', recursive=True) \
+ glob.glob(folder + '/**/*.iges', recursive=True) \
+ glob.glob(folder + '/**/*.igs', recursive=True) \
+ glob.glob(folder + '/**/*.brep', recursive=True) \
+ glob.glob(folder + '/**/*.geo', recursive=True)
model_files += glob.glob(folder + '/**/*.msh', recursive=True) \
+ glob.glob(folder + '/**/*.mesh', recursive=True) \
+ glob.glob(folder + '/**/*.vtk', recursive=True) \
+ glob.glob(folder + '/**/*.stl', recursive=True)
setup_GUI(args)
set_main_window_title("Gmsh launcher")
set_main_window_size(300, 900)
setup_dearpygui()
i = 0
prev_figures = last_figures
while is_dearpygui_running():
render_dearpygui_frame()
set_value("cmd_text",update_command(args))
if len(last_figures) > 0:
if last_figures != prev_figures:
prev_figures = last_figures
if len(last_figures) == 4:
draw_image("figures_png", last_figures[0], [0,0],pmax=[150,150])
draw_image("figures_png", last_figures[1], [150,0],pmax=[300,150])
draw_image("figures_png", last_figures[2], [0,150],pmax=[150,300])
draw_image("figures_png", last_figures[3], [150,150],pmax=[300,300])
else:
draw_image("figures_png", last_figures[0], [0,0],pmax=[300,300])
cleanup_dearpygui()
#!/usr/bin/python3
import subprocess
import sys
import os
import yaml
import glob
import argparse
from math import inf
from shutil import copyfile
try:
import gmsh
except ImportError:
sys.exit("Failed to import gmsh")
def model_stats():
nodes = gmsh.model.getEntities(0)
curves = gmsh.model.getEntities(1)
surfaces = gmsh.model.getEntities(2)
volumes = gmsh.model.getEntities(3)
return len(nodes), len(curves), len(surfaces), len(volumes)
def get_fltk_views():
volumes = gmsh.model.getEntities(3)
xmin, ymin, zmin = inf, inf, inf
xmax, ymax, zmax = -inf, -inf, -inf
for ent in volumes:
x,y,z,X,Y,Z = gmsh.model.getBoundingBox(3,ent[1])
if x<xmin:
xmin = x
if y<ymin:
ymin = y
if z<zmin:
zmin = z
if X>xmax:
xmax = X
if Y>ymax:
ymax = Y
if Z>zmax:
zmax = Z
# barycenter = ((xmax+xmin)/2,(ymax+ymin)/2,(zmax+zmin)/2)
dl = ((xmax-xmin),(ymax-ymin),(zmax-zmin))
scaling = (dl[0]**2+dl[1]**2+dl[2]**2)**-.5
while scaling < .5:
scaling *= 1.25
fltk_views = [
[["General.RotationX",0],["General.RotationY",0],["General.RotationZ",0],["Mesh.Clip",0] ,["General.ScaleX",1],["General.ScaleY",1],["General.ScaleZ",1]],
[["General.RotationX",0],["General.RotationY",-90],["General.RotationZ",0],["Mesh.Clip",0],["General.ScaleX",1],["General.ScaleY",1],["General.ScaleZ",1]],
[["General.RotationX",-90],["General.RotationY",0],["General.RotationZ",0],["Mesh.Clip",0],["General.ScaleX",1],["General.ScaleY",1],["General.ScaleZ",1]],
[["General.RotationX",30],["General.RotationY",60],["General.RotationZ",120],["Mesh.Clip",0],["General.ScaleX",scaling],["General.ScaleY",scaling],["General.ScaleZ",scaling]],
]
return fltk_views
parser = argparse.ArgumentParser(description='Process one step model with gmsh')
parser.add_argument('step', type=str, help='Path to input step file')
parser.add_argument('output', type=str, help='Path where to copy the input if tet-meshable')
args = parser.parse_args()
assert os.path.isfile(args.step)
print("Screenshot for CAD model", args.step,"...")
gmsh.initialize([],readConfigFiles=False)
gmsh.option.setNumber("General.BackgroundGradient",0)
gmsh.option.setNumber("General.Antialiasing", 1)
gmsh.option.setNumber("General.Trackball",0)
gmsh.option.setNumber("General.SmallAxes",0)
gmsh.option.setNumber("Geometry.OCCImportLabels", 0)
gmsh.option.setNumber("Geometry.Points", 0)
gmsh.option.setNumber("Geometry.Lines", 1)
gmsh.option.setNumber("Geometry.LineWidth", 2)
gmsh.option.setNumber("Geometry.LineType", 1)
gmsh.option.setNumber("Geometry.NumSubEdges", 100)
gmsh.option.setNumber("Geometry.Surfaces", 1)
gmsh.option.setNumber("Geometry.SurfaceType", 2)
gmsh.option.setColor("Geometry.Lines", 204, 102, 102)
gmsh.option.setColor("Geometry.Surfaces", 102, 153, 204)
gmsh.merge(args.step)
nn, nc, ns, nv = model_stats()
print("- CAD stats: {} nodes, {} curves, {} surfaces, {} volumes".format(nn,nc,ns,nv))
views = get_fltk_views()
for i,vopt in enumerate(views):
for opt in vopt:
gmsh.option.setNumber(opt[0],opt[1])
gmsh.fltk.update()
png = args.output + "_" + str(i) + ".png"
print("-",png)
gmsh.write(png)
gmsh.finalize()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment