From c70acf94ced812e1442664ae6f3555032c017034 Mon Sep 17 00:00:00 2001 From: fsalmoir Date: Fri, 22 Jul 2016 11:27:04 +0200 Subject: [PATCH 1/2] changed picture and caption of gui in readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6a53ccfc..bf20b928 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ Pick the geometry, the parameters file, set the name of the output and decide wh

+

+

PyGeM GUI: how it appears when it pops up.

From f05d16d64f4170d2b3ad037d31b9ea61811a134d Mon Sep 17 00:00:00 2001 From: fsalmoir Date: Fri, 22 Jul 2016 15:18:41 +0200 Subject: [PATCH 2/2] now matplotlib figures are centered on the geometry --- README.md | 2 +- pygem/igeshandler.py | 19 ++++++++++++++----- pygem/stlhandler.py | 15 ++++++++++++--- pygem/vtkhandler.py | 16 +++++++++++++--- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index bf20b928..b5fe824d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ See the **Examples** section below to have an idea of the potential of this pack ## Graphic Unit Interface **PyGeM** is now provided with a very basic Graphic Unit Interface (GUI) that, in Ubuntu environment, looks like the one depicted below. This feature can be easily used even by the pythonists beginners with not much effort. Up to now, PyGeM GUI works on linux and Mac OS X computers. -Pick the geometry, the parameters file, set the name of the output and decide whether dump the FFD lattice or not. Now just click on the `Run PyGeM` button and that is it. +Pick the geometry, the parameters file, set the name of the output and decide whether dump the FFD lattices or not. Now just click on the `Run PyGeM` button and that is it.

diff --git a/pygem/igeshandler.py b/pygem/igeshandler.py index 794d6ab5..300dbecb 100644 --- a/pygem/igeshandler.py +++ b/pygem/igeshandler.py @@ -246,11 +246,20 @@ def plot(self, plot_file=None, save_fig=False): # Load the STL files and add the vectors to the plot stl_mesh = mesh.Mesh.from_file('aux_figure.stl') os.remove('aux_figure.stl') - axes.add_collection3d(mplot3d.art3d.Poly3DCollection(stl_mesh.vectors)) - - # Auto scale to the mesh size - scale = stl_mesh.points.flatten(-1) - axes.auto_scale_xyz(scale, scale, scale) + axes.add_collection3d(mplot3d.art3d.Poly3DCollection(stl_mesh.vectors/1000)) + + ## Get the limits of the axis and center the geometry + max_dim = np.array([np.max(stl_mesh.vectors[:,:,0])/1000, \ + np.max(stl_mesh.vectors[:,:,1])/1000, \ + np.max(stl_mesh.vectors[:,:,2])/1000]) + min_dim = np.array([np.min(stl_mesh.vectors[:,:,0])/1000, \ + np.min(stl_mesh.vectors[:,:,1])/1000, \ + np.min(stl_mesh.vectors[:,:,2])/1000]) + + max_lenght = np.max(max_dim - min_dim) + axes.set_xlim(-.6*max_lenght + (max_dim[0]+min_dim[0])/2, .6*max_lenght + (max_dim[0]+min_dim[0])/2) + axes.set_ylim(-.6*max_lenght + (max_dim[1]+min_dim[1])/2, .6*max_lenght + (max_dim[1]+min_dim[1])/2) + axes.set_zlim(-.6*max_lenght + (max_dim[2]+min_dim[2])/2, .6*max_lenght + (max_dim[2]+min_dim[2])/2) # Show the plot to the screen if not save_fig: diff --git a/pygem/stlhandler.py b/pygem/stlhandler.py index 0378e6d7..ddac429f 100644 --- a/pygem/stlhandler.py +++ b/pygem/stlhandler.py @@ -104,9 +104,18 @@ def plot(self, plot_file=None, save_fig=False): stl_mesh = mesh.Mesh.from_file(plot_file) axes.add_collection3d(mplot3d.art3d.Poly3DCollection(stl_mesh.vectors)) - # Auto scale to the mesh size - scale = stl_mesh.points.flatten(-1) - axes.auto_scale_xyz(scale, scale, scale) + ## Get the limits of the axis and center the geometry + max_dim = np.array([np.max(stl_mesh.vectors[:,:,0]), \ + np.max(stl_mesh.vectors[:,:,1]), \ + np.max(stl_mesh.vectors[:,:,2])]) + min_dim = np.array([np.min(stl_mesh.vectors[:,:,0]), \ + np.min(stl_mesh.vectors[:,:,1]), \ + np.min(stl_mesh.vectors[:,:,2])]) + + max_lenght = np.max(max_dim - min_dim) + axes.set_xlim(-.6*max_lenght + (max_dim[0]+min_dim[0])/2, .6*max_lenght + (max_dim[0]+min_dim[0])/2) + axes.set_ylim(-.6*max_lenght + (max_dim[1]+min_dim[1])/2, .6*max_lenght + (max_dim[1]+min_dim[1])/2) + axes.set_zlim(-.6*max_lenght + (max_dim[2]+min_dim[2])/2, .6*max_lenght + (max_dim[2]+min_dim[2])/2) # Show the plot to the screen if not save_fig: diff --git a/pygem/vtkhandler.py b/pygem/vtkhandler.py index 7c5a6d08..e152c70f 100644 --- a/pygem/vtkhandler.py +++ b/pygem/vtkhandler.py @@ -141,9 +141,19 @@ def plot(self, plot_file=None, save_fig=False): tri.set_color('b') tri.set_edgecolor('k') axes.add_collection3d(tri) - - scale = vtx.flatten(-1) - axes.auto_scale_xyz(scale, scale, scale) + + ## Get the limits of the axis and center the geometry + max_dim = np.array([np.max(vtx[:,:,0]), \ + np.max(vtx[:,:,1]), \ + np.max(vtx[:,:,2])]) + min_dim = np.array([np.min(vtx[:,:,0]), \ + np.min(vtx[:,:,1]), \ + np.min(vtx[:,:,2])]) + + max_lenght = np.max(max_dim - min_dim) + axes.set_xlim(-.6*max_lenght + (max_dim[0]+min_dim[0])/2, .6*max_lenght + (max_dim[0]+min_dim[0])/2) + axes.set_ylim(-.6*max_lenght + (max_dim[1]+min_dim[1])/2, .6*max_lenght + (max_dim[1]+min_dim[1])/2) + axes.set_zlim(-.6*max_lenght + (max_dim[2]+min_dim[2])/2, .6*max_lenght + (max_dim[2]+min_dim[2])/2) # Show the plot to the screen if not save_fig: