Skip to content

Commit

Permalink
Update/Bugfix mesh-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
MuellerSeb committed Jul 18, 2019
1 parent ae96c0e commit 6a0489b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 1 addition & 3 deletions ogs5py/fileclasses/mpd/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""
Class for the ogs MEDIUM_PROPERTIES_DISTRIBUTED file.
"""
"""Class for the ogs MEDIUM_PROPERTIES_DISTRIBUTED file."""

from __future__ import absolute_import, division, print_function
import os
Expand Down
4 changes: 2 additions & 2 deletions ogs5py/fileclasses/msh/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def generate(self, generator="rectangular", **kwargs):
"""
self._dict = getattr(gen, generator)(**kwargs)

def show(self, show_element_id=True):
def show(self, show_material_id=True):
"""
Display the mesh colored by its material ID.
Expand All @@ -967,7 +967,7 @@ def show(self, show_element_id=True):
"""
from ogs5py.fileclasses.msh.viewer import show_mesh

show_mesh(self._dict, show_element_id=show_element_id)
show_mesh(self._dict, show_material_id=show_material_id)

#######################
### Special methods
Expand Down
4 changes: 3 additions & 1 deletion ogs5py/fileclasses/msh/msh_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ def import_mesh(
If there is any "vertex" in the element data, it will be removed.
"""
mesh = mio.read(filepath, file_format=file_format)
out = convert_meshio(mesh, ignore_unknown, import_dim)
out = convert_meshio(
mesh, ignore_unknown, import_dim, element_id_name, material_id_name
)

return out

Expand Down
15 changes: 8 additions & 7 deletions ogs5py/fileclasses/msh/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import tempfile
import numpy as np
from ogs5py.fileclasses.msh.tools import export_mesh
from ogs5py.fileclasses.msh.msh_io import export_mesh

os.environ["QT_API"] = "pyqt"
os.environ["ETS_TOOLKIT"] = "qt4"
Expand All @@ -20,7 +20,7 @@
MAYA_AVAIL = False


def show_mesh(mesh, show_element_id=True):
def show_mesh(mesh, show_material_id=True):
"""
Display a given mesh colored by its material ID.
Expand All @@ -44,7 +44,7 @@ def show_mesh(mesh, show_element_id=True):
contains material ids for each element sorted by element types
element_id : dictionary
contains element ids for each element sorted by element types
show_element_id : bool, optional
show_material_id : bool, optional
Here you can specify if the mesh should be colored by material_id.
Default: True
Expand Down Expand Up @@ -72,9 +72,9 @@ def show_mesh(mesh, show_element_id=True):
max_id = np.max((max_id, np.max(mesh["material_id"][matid])))
id_no = int(max_id - min_id + 1)
# create a temp-file which contains a vtk version of the mesh
vtkfile = tempfile.NamedTemporaryFile(suffix=".vtk")
vtkfile = tempfile.NamedTemporaryFile(suffix=".vtu")
# export the mesh to the temp vtk file
export_mesh(vtkfile.name, mesh, export_material_id=show_element_id)
export_mesh(vtkfile.name, mesh, export_material_id=show_material_id)
print("temp vtk file for mayavi:")
print(vtkfile.name)
# load the vtk file to mayavi's mlab
Expand All @@ -87,7 +87,9 @@ def show_mesh(mesh, show_element_id=True):
surface.actor.property.interpolation = "flat"
# settings for the material ID
# surface.parent.scalar_lut_manager.lut_mode = "Set1"
if show_element_id:
if show_material_id:
surface.parent.parent._cell_scalars_name_changed("material_id")
surface.parent.parent.update()
surface.parent.scalar_lut_manager.use_default_range = False
surface.parent.scalar_lut_manager.data_range = [min_id, max_id]
surface.parent.scalar_lut_manager.number_of_colors = max(id_no, 2)
Expand All @@ -97,7 +99,6 @@ def show_mesh(mesh, show_element_id=True):
surface.parent.scalar_lut_manager.shadow = True
surface.parent.scalar_lut_manager.show_scalar_bar = True
surface.parent.scalar_lut_manager.scalar_bar.label_format = "%.0f"
# mlab.colorbar(surface, orientation='vertical', label_fmt='%.0f')
# give it a name
surface.name = "OGS mesh"
# show it
Expand Down

0 comments on commit 6a0489b

Please sign in to comment.