From e3b6c4ea926cdd584b86e5bd2bfdbb2d904359fc Mon Sep 17 00:00:00 2001 From: Ben Heasly <benjamin.heasly@gmail.com> Date: Fri, 3 Feb 2017 16:13:04 -0500 Subject: [PATCH] fetch reference data with Remote Data Toolbox --- Test/Interactive/rtbFetchReferenceData.m | 64 ++++++++++++++++++++++++ Test/Interactive/rtbFindRenderings.m | 4 -- Test/Interactive/rtbRenderingRecord.m | 20 +++++++- 3 files changed, 83 insertions(+), 5 deletions(-) create mode 100644 Test/Interactive/rtbFetchReferenceData.m diff --git a/Test/Interactive/rtbFetchReferenceData.m b/Test/Interactive/rtbFetchReferenceData.m new file mode 100644 index 0000000..8b400f6 --- /dev/null +++ b/Test/Interactive/rtbFetchReferenceData.m @@ -0,0 +1,64 @@ +function [renderings, referenceRoot, artifact] = rtbFetchReferenceData(recipeName, varargin) +% Fetch a reference rendering and make it available locally. +% +% renderings = rtbFetchReferenceData(recipeName) fetches a reference data +% zip-file from the default brainard-archiva server. The given recipeName +% must be the name of an rtb example recipe, like 'rtbMakeDragon'. Expands +% the fetched zip file into the current directory. Returns a struct array +% of rendering data files that were found in the reference data. +% +% Also returns the path to the root folder where the zip file was expanded. +% Also returns the RemoteDataToolbox artifact record for the fetched data. +% +% rtbFetchReferenceData( ... 'rdtConfig', rdtConfig) specify the Remote +% Data Toolbox configuration to use. The default is 'render-toolbox'. +% +% rtbFetchReferenceData( ... 'remotePath', remotePath) specify the Remote +% Data Toolbox artifact path to use. The default is 'reference-data'. +% +% rtbFetchReferenceData( ... 'referenceVersion', referenceVersion) specify +% the Remote Data Toolbox artifact version to fetch. The default is '+', +% the latest available. +% +% rtbFetchReferenceData( ... 'referenceRoot', referenceRoot) specify the +% root folder where to expand the fetched zip file. The default is pwd(). +% +% [renderings, referenceRoot, artifact] = rtbFetchReferenceData(recipeName, varargin) +% +%%% RenderToolbox4 Copyright (c) 2012-2017 The RenderToolbox Team. +%%% About Us://github.com/RenderToolbox/RenderToolbox4/wiki/About-Us +%%% RenderToolbox4 is released under the MIT License. See LICENSE file. + +parser = inputParser(); +parser.addRequired('recipeName', @ischar); +parser.addParameter('rdtConfig', 'render-toolbox'); +parser.addParameter('remotePath', 'reference-data', @ischar); +parser.addParameter('referenceVersion', '+', @ischar); +parser.addParameter('referenceRoot', pwd(), @ischar); +parser.parse(recipeName, varargin{:}); +recipeName = parser.Results.recipeName; +rdtConfig = parser.Results.rdtConfig; +remotePath = parser.Results.remotePath; +referenceVersion = parser.Results.referenceVersion; +referenceRoot = parser.Results.referenceRoot; + + +%% Get a whole recipe from the server. +artifactPath = fullfile(remotePath, recipeName); +[fileName, artifact] = rdtReadArtifact(rdtConfig, artifactPath, recipeName, ... + 'version', referenceVersion, ... + 'type', 'zip'); + +if isempty(fileName) + renderings = []; + artifact = []; + return; +end + + +%% Explode renderings it into the destination folder. +destination = fullfile(referenceRoot, recipeName); +unzip(fileName, destination); + +% scan for rendering records +renderings = rtbFindRenderings(destination); diff --git a/Test/Interactive/rtbFindRenderings.m b/Test/Interactive/rtbFindRenderings.m index 6411417..cdde19c 100644 --- a/Test/Interactive/rtbFindRenderings.m +++ b/Test/Interactive/rtbFindRenderings.m @@ -63,11 +63,7 @@ for ff = 1:nFiles renderingsFolderIndex = find(isRenderingsFolder, 1, 'last'); % recipe name comes just before renderingsFolderName - % ignore "rtb" prefix if any recipeName = pathParts{renderingsFolderIndex - 1}; - if strncmp(recipeName, 'rtb', 3) - recipeName = recipeName(4:end); - end % renderer name comes just after renderingsFolderName, if any if nPathParts > renderingsFolderIndex diff --git a/Test/Interactive/rtbRenderingRecord.m b/Test/Interactive/rtbRenderingRecord.m index 1a57ff0..ce80687 100644 --- a/Test/Interactive/rtbRenderingRecord.m +++ b/Test/Interactive/rtbRenderingRecord.m @@ -26,5 +26,23 @@ parser.addParameter('imageName', '',@ischar); parser.addParameter('fileName', '', @ischar); parser.parse(varargin{:}); -% let the parser do all the work +% let the parser do most of the work record = parser.Results; + +% format an identifier useful for comparing records with eg setdiff() +recipeName = record.recipeName; +if strncmp(recipeName, 'rtb', 3) + recipeName = recipeName(4:end); +end + +if isempty(record.imageNumber) + record.identifier = sprintf('%s-%s-%s', ... + recipeName, ... + record.rendererName, ... + record.imageName); +else + record.identifier = sprintf('%s-%s-%d', ... + recipeName, ... + record.rendererName, ... + record.imageNumber); +end -- GitLab