Skip to content

Commit

Permalink
Allows the user to change the resolution of the render window and the…
Browse files Browse the repository at this point in the history
… output file
  • Loading branch information
delaossa committed Oct 11, 2023
1 parent 82d2679 commit 81a7fde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 5 additions & 2 deletions visualpic/ui/basic_render_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
16 changes: 13 additions & 3 deletions visualpic/visualization/vtk_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -337,16 +341,22 @@ 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:
self._make_timestep_render(timestep, ts_is_index)
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()

Expand Down

0 comments on commit 81a7fde

Please sign in to comment.