Home > polypedal > cartperturb > topTrackSanityCheck.m

topTrackSanityCheck

PURPOSE ^

TOPMARKERSANITYCHECK Sanity check for top marker tracks in specified files

SYNOPSIS ^

function [] = topMarkerSanityCheck( filespec )

DESCRIPTION ^

 TOPMARKERSANITYCHECK Sanity check for top marker tracks in specified files
   topMarkerSanityCheck( filespec )
 INPUT:
   filespec -- string -- argument to dir command specifying files,
     e.g. 'mov/*.avi' or 'mov/20080806-1511-r4.avi'
         -- or --
   filespec -- cell array of strings giving argument to dir command specifying files,
     e.g. {'mov/20080806*avi','mov/20080806-1511-r4.avi'}

 $Revision: 1.12 $
 By Sam Burden, Berkeley 2008

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [] = topMarkerSanityCheck( filespec )
0002 % TOPMARKERSANITYCHECK Sanity check for top marker tracks in specified files
0003 %   topMarkerSanityCheck( filespec )
0004 % INPUT:
0005 %   filespec -- string -- argument to dir command specifying files,
0006 %     e.g. 'mov/*.avi' or 'mov/20080806-1511-r4.avi'
0007 %         -- or --
0008 %   filespec -- cell array of strings giving argument to dir command specifying files,
0009 %     e.g. {'mov/20080806*avi','mov/20080806-1511-r4.avi'}
0010 %
0011 % $Revision: 1.12 $
0012 % By Sam Burden, Berkeley 2008
0013 
0014 % Parse arguments
0015 if nargin < 1
0016   error('Must give a filespec, e.g. ''mov/*.avi'' or ''mov/20080806-1511-r4.avi''.');
0017 end
0018 
0019 % Get list of movies
0020 files = fileList(filespec);
0021 
0022 % Warn user if no files were found
0023 if length(files) == 0
0024   disp(['Warning:  no movies found for file specification ',files]);
0025 end
0026 
0027 ninterpolate = 9;
0028 
0029 % Loop over files
0030 for f = 1:length(files)
0031   
0032   % Get directory containing file
0033   directory = files(f).directory;
0034     
0035   % Get file name prefix
0036   prefix = strtok(files(f).name,'.');
0037 
0038   % If top trajectory file exists
0039   if exist([directory,prefix,'-top-track.mat'],'file') || exist([directory,prefix,'-top-wp.mat'],'file')
0040         
0041     disp(['Top sanity check:  ',directory,prefix,'.avi . . .']);
0042     
0043     % Initialize trajectories
0044     trajF = [];
0045     trajB = [];
0046     traj = [];
0047         
0048     % Create figure
0049     close all;
0050     sfig = figure;
0051     axis equal;
0052     hold on;
0053     
0054     % Initialize legend entries
0055     leg = {};
0056     
0057     % If [prefix]-top-track.mat exists
0058     if exist([directory,prefix,'-top-track.mat'],'file')
0059       
0060       disp(['Loading ',directory,prefix,'-top-track.mat . .']);
0061     
0062       % Load top marker track
0063       load([directory,prefix,'-top-track.mat'],'top');
0064       
0065       % Create forward-time trajectory
0066       for w = 1:size(top.waypoints,1)-1
0067         if w <= length(top.trackF) && ~isempty(top.trackF{w})
0068           trajF(top.waypoints(w,3):top.waypoints(w+1,3)) = top.trackF{w}.traj;
0069         else
0070           trajF(top.waypoints(w,3):top.waypoints(w+1,3)) = nan;
0071         end
0072       end
0073     
0074       % Create backward-time trajectory
0075       for w = size(top.waypoints,1):-1:2
0076         if w <= length(top.trackB) && ~isempty(top.trackB{w})
0077           trajB(top.waypoints(w,3):-1:top.waypoints(w-1,3)) = top.trackB{w}.traj;
0078         else
0079           trajB(top.waypoints(w,3):-1:top.waypoints(w-1,3)) = nan;
0080         end
0081       end
0082       
0083       if ~isempty(trajF)
0084         % Plot trajectories
0085         plot(trajF, 'b', 'LineWidth', 2);
0086         plot(trajB, 'g', 'LineWidth', 2);
0087       
0088         % Add entries to legend
0089         leg = {leg{:}, 'forward-time', 'backward-time'};
0090       end
0091       
0092     end % If [prefix]-top-track.mat exists
0093     
0094     
0095     % If [prefix]-top-wp.mat exists
0096     if exist([directory,prefix,'-top-wp.mat'],'file')
0097     
0098       disp(['Loading ',directory,prefix,'-top-wp.mat . .']);
0099     
0100       % Load top marker waypoints
0101       load([directory,prefix,'-top-wp.mat'],'top');
0102       
0103       if isempty(top.waypoints)
0104         disp(['Warning:  no waypoints in file.']);
0105         continue;
0106       end
0107       
0108       % Create composite trajectory
0109       traj = [];
0110       if isfield(top,'trajectory')
0111         traj = top.trajectory;
0112       end
0113       
0114       if ~isempty(traj)
0115         % Plot trajectory
0116         plot(traj, 'r');
0117       
0118         % Add entry to legend
0119         leg = {leg{:}, 'composite'};
0120       end
0121       
0122     end % If [prefix]-top-wp.mat exists
0123     
0124     
0125     % Get framesource from framesource ini
0126 %     src = srcFromIni(top.srcini(1));
0127 %     src{2} = newFrameSourceResampler(src, top.waypoints(1,3):top.waypoints(end,3));
0128       
0129     
0130     % Plot waypoints
0131     plot(top.waypoints(:,[1 2]) * [1; i],'ro', 'MarkerSize', 10);
0132     plot(top.waypoints(:,[1 2]) * [1; i],'r.', 'MarkerSize', 10);
0133     leg = {leg{:}, 'waypoints'};
0134     
0135     % Label waypoints
0136     offset = 10;
0137     for w = 1:size(top.waypoints,1)
0138       text(top.waypoints(w,1)+offset,top.waypoints(w,2),[num2str(top.waypoints(w,3))],'VerticalAlignment','middle');
0139     end
0140     
0141     % Add legend
0142     legend(leg);
0143     
0144     
0145     % Update display
0146     drawnow;
0147     
0148     % Save sanity check figure
0149     img = getframe(sfig);
0150     imwrite(img.cdata, [directory,prefix,'-top-check.png'], 'png');
0151   end
0152 end
0153     
0154

Generated on Mon 02-Aug-2010 16:44:38 by m2html © 2003