Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rgerum/saenopy
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbhr committed Aug 2, 2023
2 parents db632d2 + 0c8e928 commit 74c057a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions saenopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
from .solver import subtract_reference_state, interpolate_mesh
from .examples import load_example
import importlib.metadata
from .gui.solver.modules.exporter.Exporter import render_image

__version__ = importlib.metadata.metadata('saenopy')['version']
2 changes: 1 addition & 1 deletion saenopy/gui/solver/modules/Regularizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def update_display(self):
colormap2=self.vtk_toolbar.colormap_chooser2.value(),
scalebar_max=self.vtk_toolbar.getScaleMax(), show_nan=self.vtk_toolbar.use_nans.value(),
display_image=display_image, show_grid=self.vtk_toolbar.show_grid.value(),
stack_shape=stack_shape)
stack_shape=stack_shape, log_scale=self.vtk_toolbar.use_log.value())
if cam_pos is not None:
self.plotter.camera_position = cam_pos
relrec = getattr(self.result.solvers[self.t_slider.value()], "relrec", None)
Expand Down
7 changes: 7 additions & 0 deletions saenopy/gui/solver/modules/VTK_Toolbar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import numpy as np
import qtawesome as qta
from qtpy import QtWidgets
import pyvista as pv
Expand Down Expand Up @@ -96,6 +97,10 @@ def __init__(self, plotter, update_display, scalbar_type="deformation", center=F
resource_icon("nan1.ico"),
], group=False, tooltip="Display nodes which do not have values associated as gray dots.")

if self.is_force_plot:
self.use_log = QtShortCuts.QInputBool(None, "log", tooltip="Display arrow length and color in logarithmic scale.")
self.use_log.valueChanged.connect(self.update_display)

self.use_nans.valueChanged.connect(self.update_display)
self.show_grid = QtShortCuts.QInputBool(None, "", True,
tooltip="Display a grid or a bounding box.", icon=[
Expand Down Expand Up @@ -240,6 +245,8 @@ def scale_max_changed(self):
def getScaleMax(self):
if self.auto_scale.value():
return None
if self.is_force_plot and self.use_log.value():
return np.log10(self.scale_max.value())
return self.scale_max.value()

def new_plotter(self, x, no_recursion=False):
Expand Down
2 changes: 2 additions & 0 deletions saenopy/gui/solver/modules/exporter/Exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Null:
self.vtk_toolbar2.auto_scale.addToLayout()
self.vtk_toolbar2.scale_max.addToLayout()
self.vtk_toolbar2.use_center.addToLayout()
self.vtk_toolbar2.use_log.addToLayout()
self.input_arrow_opacity2 = QtShortCuts.QInputNumber(None, "opacity", 1, min=0, max=1,
float=True, step=0.1)
self.input_arrow_opacity2.valueChanged.connect(self.update_display)
Expand Down Expand Up @@ -430,6 +431,7 @@ class Null:
"autoscale": self.vtk_toolbar2.auto_scale,
"scale_max": self.vtk_toolbar2.scale_max,
"use_center": self.vtk_toolbar2.use_center,
"use_log": self.vtk_toolbar2.use_log,
"colormap": self.vtk_toolbar2.colormap_chooser,
"arrow_scale": self.vtk_toolbar2.arrow_scale,
"arrow_opacity": self.input_arrow_opacity2,
Expand Down
15 changes: 11 additions & 4 deletions saenopy/gui/solver/modules/exporter/ExporterRender3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def render_3d_arrows(params, result, plotter):
"arrows",
("time", "t"),
("deformation_arrows", ("scale_max", "autoscale", "skip", "arrow_opacity", "colormap", "arrow_scale")),
("force_arrows", ("scale_max", "autoscale", "skip", "arrow_opacity", "colormap", "arrow_scale", "use_center")),
("force_arrows", ("scale_max", "autoscale", "skip", "arrow_opacity", "colormap", "arrow_scale", "use_center", "use_log")),
]
params, changed = filter_params(params, used_values, getattr(plotter, "previous_plot_params", {}))

Expand All @@ -157,7 +157,7 @@ def render_3d_arrows(params, result, plotter):
return

show_nan = params["use_nans"]
scalebar_max = params_arrows["scale_max"] if params_arrows["autoscale"] else None
scalebar_max = params_arrows["scale_max"] if not params_arrows["autoscale"] else None
colormap = params_arrows["colormap"]
skip = params_arrows["skip"]
arrow_opacity = params_arrows["arrow_opacity"]
Expand Down Expand Up @@ -186,7 +186,14 @@ def render_3d_arrows(params, result, plotter):
factor = 0.1 * params_arrows["arrow_scale"]
if name == "forces":
# scale forces to pN
point_cloud.point_data[name + "_mag2"] = 1e12*point_cloud.point_data[name + "_mag"].copy()
if params_arrows["use_log"]:
if scalebar_max is not None:
scalebar_max = np.log10(scalebar_max)
point_cloud.point_data[name + "_mag2"] = np.log10(1e12 * point_cloud.point_data[name + "_mag"].copy())
point_cloud.point_data[name + "_mag2"] *= (
point_cloud.point_data[name + "_mag2"] > point_cloud.point_data[name + "_mag2"] * 0.1)
else:
point_cloud.point_data[name + "_mag2"] = 1e12*point_cloud.point_data[name + "_mag"].copy()
factor = 0.15 * params_arrows["arrow_scale"]
# hide nans
point_cloud.point_data[name + "_mag2"][nan_values] = 0
Expand Down Expand Up @@ -235,7 +242,7 @@ def render_3d_arrows(params, result, plotter):

# plot center points if desired
if params_arrows.get("use_center", False):
center = obj.get_center(mode="Force")
center = result.solvers[params["time"]["t"]].get_center(mode="Force")
plotter.add_points(np.array([center])*1e6, color='m', point_size=10, render=False, name="center")
else:
plotter.remove_actor("center")
Expand Down
8 changes: 6 additions & 2 deletions saenopy/gui/solver/modules/showVectorField.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def showVectorField2(self, M, points_name):

def showVectorField(plotter: QtInteractor, obj: Solver, field: np.ndarray, name: str, center=None, show_nan=True, stack_shape=None,
show_all_points=False, factor=.1, scalebar_max=None, display_image=None, show_grid=True,
colormap="turbo", colormap2=None, stack_min_max=None, arrow_opacity=1, skip=1):
colormap="turbo", colormap2=None, stack_min_max=None, arrow_opacity=1, skip=1, log_scale=False):
# ensure that the image is either with color channels or no channels
if (display_image is not None) and (display_image[0].shape[2] == 1):
display_image[0] = display_image[0][:, :, 0]
Expand Down Expand Up @@ -110,7 +110,11 @@ def showVectorField(plotter: QtInteractor, obj: Solver, field: np.ndarray, name:
point_cloud.point_data[name + "_mag2"] = 1e6*point_cloud.point_data[name + "_mag"].copy()
if name == "forces":
# scale forces to pN
point_cloud.point_data[name + "_mag2"] = 1e12*point_cloud.point_data[name + "_mag"].copy()
if log_scale:
point_cloud.point_data[name + "_mag2"] = np.log10(1e12*point_cloud.point_data[name + "_mag"].copy())
point_cloud.point_data[name + "_mag2"] *= (point_cloud.point_data[name + "_mag2"] > point_cloud.point_data[name + "_mag2"]*0.1)
else:
point_cloud.point_data[name + "_mag2"] = 1e12 * point_cloud.point_data[name + "_mag"].copy()
# hide nans
point_cloud.point_data[name + "_mag2"][nan_values] = 0
# show nans
Expand Down

0 comments on commit 74c057a

Please sign in to comment.