Code covered by the BSD License  

Highlights from
Vector Field TB

Vector Field TB

by

 

27 Jun 2012 (Updated )

A group of class to perform vector field (DPIV) data analysis and visualization

convert_vortex_data(vx_data, sf_obj, varargin)
function out = convert_vortex_data(vx_data, sf_obj, varargin)
% CONVERT_VORTEX_DATA converts vortex_traking output
%   OUT = CONVERT_VORTEX_DATA(VX_DATA, SF_OBJ) converts data obtained by
%   VORTEX_TRACKING function from pixel units to the one defined in the 
%   SF_OBJ defined units (default SF_OBJ value is 'mm').
%
%   OUT = CONVERT_VORTEX_DATA(VX_DATA, SF_OBJ, UNIT_OF_MEASURE) converts
%   from pixel to user defined unit. Accepted value for UNIT_OF_MEASURE
%   are: 'km', 'hm', 'dam', 'm', 'dm', 'cm', 'mm'.
%
%   See also: vortex_tracking, extract_vortex_data

% Original unit of measure
switch lower(sf_obj.fieldInfo.unitx)
    case 'mm'
        sf_unit = 10^(-3);
    case 'cm'
        sf_unit = 10^(-2);
    case 'dm'
        sf_unit = 10^(-1);
    case 'm'
        sf_unit = 10^0;
    case 'dam'
        sf_unit = 10^1;
    case 'hm'
        sf_unit = 10^2;
    case 'km'
        sf_unit = 10^3;
    otherwise
        % ERROR
end

% Required unit of measure
if ~isempty(varargin)
    switch lower(varargin{1})
        case 'mm'
            unit        = 10^(-3);
            unit_name   = 'mm';
        case 'cm'
            unit        = 10^(-2);
            unit_name   = 'cm';
        case 'dm'
            unit        = 10^(-1);
            unit_name   = 'dm';
        case 'm'
            unit        = 10^0;
            unit_name   = 'm';
        case 'dam'
            unit        = 10^1;
            unit_name   = 'dam';
        case 'hm'
            unit        = 10^2;
            unit_name   = 'hm';
        case 'km'
            unit        = 10^3;
            unit_name   = 'km';
        otherwise
            % ERROR
    end
else
    unit        = sf_unit;
    unit_name   = sf_obj.fieldInfo.unitx;
end

% Compute conversion ratio
ratio = abs(diff(sf_obj.x(1:2))) .* (sf_unit./unit);

fprintf('Converting vortex data: px -> %s\n',unit_name);
fprintf('1 px -> %3.2f %s\n',ratio, unit_name);
fprintf('--------------------------------\n');

opt = ['%0', num2str(ndigits(vx_data.numVortex)), 'd'];

% Output data
out = vx_data;

for k = 1:vx_data.numVortex
    fprintf(['Converting vortex V' opt '\n'],k);
    
    out.(['V' num2str(k)]).pos                      = out.(['V' num2str(k)]).pos .* ratio;
    out.(['V' num2str(k)]).radius                   = out.(['V' num2str(k)]).radius .* ratio;
    
    % Vortex measures
    out.(['V' num2str(k)]).Area                     = out.(['V' num2str(k)]).Area .* (ratio.^2);
    out.(['V' num2str(k)]).Circulation_circle       = out.(['V' num2str(k)]).Circulation_circle .* (ratio.^2);
    out.(['V' num2str(k)]).Circulation_circle_mean  = out.(['V' num2str(k)]).Circulation_circle_mean .* (ratio^2);
    out.(['V' num2str(k)]).Circulation_bBox         = out.(['V' num2str(k)]).Circulation_bBox .* (ratio^2);
    out.(['V' num2str(k)]).NumPixel                 = out.(['V' num2str(k)]).NumPixel; %.* ratio;
    out.(['V' num2str(k)]).Vorticity_circle         = out.(['V' num2str(k)]).Vorticity_circle; %.* ratio;
    out.(['V' num2str(k)]).Vorticity_bBox           = out.(['V' num2str(k)]).Vorticity_bBox; %.* ratio;
end
fprintf('\n--------------done--------------\n');

Contact us