From 81a7fdec3f8f1943b8d76b0ae65bb79df3e7c5c0 Mon Sep 17 00:00:00 2001 From: delaossa Date: Wed, 11 Oct 2023 11:20:31 +0200 Subject: [PATCH] Allows the user to change the resolution of the render window and the output file --- visualpic/ui/basic_render_window.py | 7 +++++-- visualpic/visualization/vtk_visualizer.py | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/visualpic/ui/basic_render_window.py b/visualpic/ui/basic_render_window.py index b6ac467..aa6f909 100644 --- a/visualpic/ui/basic_render_window.py +++ b/visualpic/ui/basic_render_window.py @@ -43,17 +43,20 @@ class BasicRenderWindow(QtWidgets.QMainWindow): """Basic Qt window for interactive visualization of 3D renders.""" - def __init__(self, vtk_visualizer, parent=None): + def __init__(self, vtk_visualizer, parent=None, resolution=None): super().__init__(parent=parent) self.vtk_vis = vtk_visualizer self.available_timesteps = self.vtk_vis.get_possible_timesteps() self.timestep_change_callbacks = [] + self.resolution = resolution self.setup_interface() self.register_ui_events() self.show() def setup_interface(self): - self.resize(600, 400) + if self.resolution is None: + self.resolution = [600, 400] + self.resize(*self.resolution) self.setWindowTitle('VisualPIC - 3D Viewer') icon_path = resource_filename('visualpic.ui.icons', 'vp_logo_sq_blue.png') diff --git a/visualpic/visualization/vtk_visualizer.py b/visualpic/visualization/vtk_visualizer.py index 88418cb..fc016a1 100644 --- a/visualpic/visualization/vtk_visualizer.py +++ b/visualpic/visualization/vtk_visualizer.py @@ -277,7 +277,7 @@ def add_species(self, species, color='w', cmap='viridis', vmax=None, 'Particle species cannot be added because it is not 3D.') def render_to_file(self, timestep, file_path, resolution=None, - ts_is_index=True): + scale_output=1, ts_is_index=True): """ Render the fields in the visualizer at a specific time step and save image to a file. @@ -298,6 +298,9 @@ def render_to_file(self, timestep, file_path, resolution=None, List containing the horizontal and vertical resolution of the rendered image. + scale : int + Scales the output resolution by this factor. + ts_is_index : bool Indicates whether the value provided in 'timestep' is the index of the time step (True) or the numerical value of the time step @@ -313,13 +316,14 @@ def render_to_file(self, timestep, file_path, resolution=None, self.window.Render() w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(self.window) + w2if.SetScale(scale_output) w2if.Update() writer = vtk.vtkPNGWriter() writer.SetFileName(file_path) writer.SetInputConnection(w2if.GetOutputPort()) writer.Write() - def show(self, timestep=0, ts_is_index=True): + def show(self, timestep=0, ts_is_index=True, resolution=None): """ Render and show the fields in the visualizer at a specific time step. @@ -337,6 +341,10 @@ def show(self, timestep=0, ts_is_index=True): the time step (True) or the numerical value of the time step (False). + resolution : list + List containing the horizontal and vertical resolution of the + rendered image. + """ # Only make render if any data has been added for visualization if len(self.volume_field_list + self.scatter_species_list) > 0: @@ -344,9 +352,11 @@ def show(self, timestep=0, ts_is_index=True): self.window.SetOffScreenRendering(0) if self.vis_config['use_qt']: app = QtWidgets.QApplication(sys.argv) - self.qt_window = BasicRenderWindow(self) + self.qt_window = BasicRenderWindow(self, resolution=resolution) app.exec_() else: + if resolution is not None: + self.window.SetSize(*resolution) self.window.Render() self.interactor.Start()