made video writing optional for performance benefits

This commit is contained in:
2025-12-23 11:50:26 -08:00
parent 557d8fe63c
commit 33036c95fd
4 changed files with 27 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
function obj = initialize(obj, domain, objective, agents, timestep, partitoningFreq, maxIter, obstacles)
function obj = initialize(obj, domain, objective, agents, timestep, partitoningFreq, maxIter, obstacles, makeVideo)
arguments (Input)
obj (1, 1) {mustBeA(obj, 'miSim')};
domain (1, 1) {mustBeGeometry};
@@ -8,11 +8,15 @@ function obj = initialize(obj, domain, objective, agents, timestep, partitoningF
partitoningFreq (:, 1) double = 0.25
maxIter (:, 1) double = 1000;
obstacles (:, 1) cell {mustBeGeometry} = cell(0, 1);
makeVideo (1, 1) logical = true;
end
arguments (Output)
obj (1, 1) {mustBeA(obj, 'miSim')};
end
% enable/disable video writer
obj.makeVideo = makeVideo;
% Define simulation time parameters
obj.timestep = timestep;
obj.maxIter = maxIter - 1;

View File

@@ -27,6 +27,7 @@ classdef miSim
partitioningTimes;
% Plot objects
makeVideo = true; % enable/disable VideoWriter (performance implications)
f = firstPlotSetup(); % main plotting tiled layout figure
connectionsPlot; % objects for lines connecting agents in spatial plots
graphPlot; % objects for abstract network graph plot

View File

@@ -7,8 +7,10 @@ function [obj] = run(obj)
end
% Start video writer
v = obj.setupVideoWriter();
v.open();
if obj.makeVideo
v = obj.setupVideoWriter();
v.open();
end
for ii = 1:size(obj.times, 1)
% Display current sim time
@@ -41,10 +43,14 @@ function [obj] = run(obj)
obj = obj.updatePlots(updatePartitions);
% Write frame in to video
I = getframe(obj.f);
v.writeVideo(I);
if obj.makeVideo
I = getframe(obj.f);
v.writeVideo(I);
end
end
% Close video file
v.close();
if obj.makeVideo
% Close video file
v.close();
end
end