Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBRT Docker Support #63

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified Admin/EpicSceneTest/Rhino/epic-scene-test.sh
100755 → 100644
Empty file.
Empty file modified Admin/ReleaseUtilities/create-release-tags.sh
100755 → 100644
Empty file.
Empty file modified Admin/mexopts/XCode-6.4-Matlab-2014b/mexopts.sh
100755 → 100644
Empty file.
14 changes: 13 additions & 1 deletion BatchRenderer/Mappings/ResolveMappingsValues.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@
map.right.value = fileInfo.resolvedPath;

if ~fileInfo.isRootFolderMatch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I like what you did here. I think copying files to the resource folder could be useful in other cases as well. Would you be interested in making this a separate behavior, independent of the renderer or Docker?

We could define a separate hint like copyResources. Then it could be

if hints.copyResources

instead of

if(hints.dockerFlag == 0 || strcmp(hints.renderer,'Mitsuba'))

A downside would be that docker users would have to remember to set the value of this new flag. But I think it would be worth it to gain a nice, modular behavior.

disp(['Using absolute resource path: ' fileInfo.resolvedPath])
if(hints.dockerFlag == 0 || strcmp(hints.renderer,'Mitsuba'))
disp(['Using absolute resource path: ' fileInfo.resolvedPath])
else
% Copy absolute resources over to recipe folder
resources = GetWorkingFolder('resources', true, hints);
copyfile(fileInfo.resolvedPath,resources);
fprintf('Copied %s to %s \n',fileInfo.resolvedPath,resources);

% Rename path to be written in generated PBRT file. We
% specify with respect to the recipe root folder.
outputLoc = fullfile('resources',hints.renderer,fileInfo.verbatimName);
map.right.value = outputLoc;
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion ExampleScenes/Dragon/MakeDragonMaterials.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%% Render with Mitsuba and PBRT.
toneMapFactor = 10;
isScale = true;
for renderer = {'PBRT', 'Mitsuba'}
for renderer = {'Mitsuba', 'PBRT'}
hints.renderer = renderer{1};
nativeSceneFiles = MakeSceneFiles(parentSceneFile, conditionsFile, mappingsFile, hints);
radianceDataFiles = BatchRender(nativeSceneFiles, hints);
Expand Down
Empty file modified ExampleScenes/LightFieldSphere/LightFieldSphere.dae
100755 → 100644
Empty file.
56 changes: 48 additions & 8 deletions RendererPlugins/PBRT/RunPBRT.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,57 @@
output = fullfile(renderings, [sceneBase '.dat']);

%% Invoke PBRT.
% set the dynamic library search path
[newLibPath, originalLibPath, libPathName] = SetRenderToolboxLibraryPath();

% find the PBRT executable
renderCommand = sprintf('%s --outfile %s %s', pbrt.executable, output, sceneCopy);
fprintf('%s\n', renderCommand);
[status, result] = RunCommand(renderCommand, hints);
if(hints.dockerFlag == 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. This is cool too.

May I propose 3 changes? I think these are just fussy organizational things.

  1. How about moving the dockerFlag into the pbrt struct, rather than hints struct. This would keep the Docker choice local to pbrt. We could think of the dockerFlag as roughly on the same level as the pbrt executable path, which is already in the pbrt struct.
  2. Instead of a true/false dockerFlag, what about a string field like dockerImageName? Then the literal value of vistalab/pbrt could be broken out and configured using this field instead of hard-coded into the function. Users could leave the field empty if they want to use local pbrt.
  3. What about moving the docker pull command into the RTB configuration script, rather than RunPBRT() itself?

If you're on board with these changes, you could edit RenderToolbox3ConfigurationTemplate to add expected fields to the pbrt struct and put the docker pull command there.

% We assume docker is installed on this system and we execute the
% function in a docker container
s = system('which docker');
if s
warning('Docker not found! \n (OSX) Are you sure you''re running MATLAB in a Docker Quickstart Terminal? ');
% TODO: add in option to run on local if docker is not found
else
% Initialize the docker container
dHub = 'vistalab/pbrt'; % Docker container at dockerhub
fprintf('Checking for most recent docker container\n');
system(sprintf('docker pull %s',dHub));

% Start the docker container that runs pbrt
dCommand = 'pbrt'; % Command run in the dockers
[~,n,e] = fileparts(sceneCopy); % Get name of pbrt input file
[~,outstem,outext] = fileparts(output); % Get name of output file

% We need this line because RTB wants to place the output in
% renderings and not just the recipe folder
outputFile = fullfile('renderings','PBRT',[outstem outext]);

% rm = clears the container when it is finished running
% -t = terminal to grab tty output
% -i = interactive (not sure it's needed)
cmd = sprintf('docker run -t -i --rm -v %s:/data %s %s /data/%s --outfile /data/%s',copyDir,dHub,dCommand,[n,e],outputFile);

% restore the library search path
setenv(libPathName, originalLibPath);
% Execute the docker call
[status,result] = system(cmd);
if status, error('Docker execution failure %s\n',result);
else disp('Docker appears to have run succesfully')
end
% disp(r);

% Tell the user where the result iss
fprintf('Wrote: %s\n',outputFile);
end
else
% Use local PBRT
% set the dynamic library search path
[newLibPath, originalLibPath, libPathName] = SetRenderToolboxLibraryPath();

% find the PBRT executable
renderCommand = sprintf('%s --outfile %s %s', pbrt.executable, output, sceneCopy);
fprintf('%s\n', renderCommand);
[status, result] = RunCommand(renderCommand, hints);

% restore the library search path
setenv(libPathName, originalLibPath);
end
%% Show a warning or figure?
if status ~= 0
warning(result)
Expand Down
1 change: 1 addition & 0 deletions Utilities/InitializeRenderToolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function InitializeRenderToolbox(isForce)
defaultConfig.isParallel = false;
defaultConfig.isPlot = true;
defaultConfig.isCaptureCommandResults = true;
defaultConfig.dockerFlag = 0;

% default dynamic library path names and default values
% these are applied automatically, via SetRenderToolboxLibraryPath()
Expand Down