📄 aft_boundingbox.m
字号:
function bbox = aft_BoundingBox(hfile)
% AFT::BoundingBox - get bounding box
%
% FORMAT: bbox = obj.BoundingBox;
%
% No input fields
%
% Output fields:
%
% bbox struct with fields
% .BBox 2x3 offset and offset + size - 1
% .CBox 2x3 offset and offset + size in 1x1x1mm coordinates
% (centered around 128, 128, 128)
% .FCube framing cube
% .DimXYZ data dimensions
% .ResXYZ data resolution
%
% Note: output is in BV's *internal* notation (axes not in TAL order!)
% Version: v0.7b
% Build: 7082922
% Date: Aug-29 2007, 10:33 PM CEST
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin < 1 || ...
numel(hfile) ~= 1 || ...
~isBVQXfile(hfile, true)
error( ...
'BVQXfile:BadArgument', ...
'Invalid call to %s.', ...
mfilename ...
);
end
% switch on filetype
sc = bvqxfile_getscont(hfile.L);
bc = sc.C;
ft = lower(sc.S.Extensions{1});
try
switch (ft)
case {'ava', 'cmp', 'glm', 'ddt', 'glm', 'msk', 'vdw', 'vmp', 'vtc'}
fc = 256;
ons = [bc.XStart, bc.YStart, bc.ZStart];
offs = [bc.XEnd, bc.YEnd, bc.ZEnd];
resxyz = bc.Resolution * ones(1, 3);
bbox = [floor(ons); ceil(offs - 1)];
dimxyz = ceil(diff(bbox) ./ resxyz);
cbox = bbox;
rcnv = true;
case {'srf'}
fc = max(2 * bc.MeshCenter);
if ~any([256, 384, 512, 1024, 2048] == fc)
fc = 256;
end
bbox = [0, 0, 0; [fc, fc, fc] - 1];
cbox = [min(bc.VertexCoordinate); max(bc.VertexCoordinate)];
dimxyz = fc;
rcnv = true;
resxyz = [1, 1, 1];
case {'vmr'}
dimxyz = size(bc.VMRData);
rcnv = bc.Convention;
if ~isfield(bc, 'OffsetX')
fc = 256;
resxyz = [1, 1, 1];
ons = floor(128 - dimxyz ./ 2);
offs = ons + dimxyz - 1;
bbox = [ons; offs];
cbox = bbox;
else
if ~isfield(bc, 'FramingCube')
fc = 256;
else
fc = bc.FramingCube;
end
if ~isfield(bc, 'VoxResX')
resxyz = [1, 1, 1];
else
resxyz = [bc.VoxResX, bc.VoxResY, bc.VoxResZ];
end
if ~any(fc == [256, 384, 512, 1024, 2048])
fc = 256;
end
fch = fc / 2;
ons = ([bc.OffsetX, bc.OffsetY, bc.OffsetZ] - fch) .* resxyz;
offs = ons + dimxyz .* resxyz;
cbox = [floor(ons); ceil(offs) - 1] + 128;
bbox = [bc.OffsetX, bc.OffsetY, bc.OffsetZ];
bbox = [bbox; (bbox + dimxyz) - 1];
end
case {'hdr'}
fc = 256;
cfr = hdr_CoordinateFrame(hfile);
ctr = cfr.Trf;
dimxyz = cfr.Dimensions(1:3);
resxyz = cfr.Resolution;
% regular cube ?
if abs(max(abs(ctr(1:3, 1))) - resxyz(1)) < 1e-4 && ...
abs(max(abs(ctr(1:3, 2))) - resxyz(2)) < 1e-4 && ...
abs(max(abs(ctr(1:3, 3))) - resxyz(3)) < 1e-4
ofmc = 128 - [ ...
ctr * (0.5 + zeros(4, 1)), ...
ctr * [0.5 + dimxyz(:); 1]]';
else
ofmc = 128 - [ ...
ctr * [ 1 ; 1 ; 1 ; 1], ...
ctr * [dimxyz(1); 1 ; 1 ; 1], ...
ctr * [ 1 ;dimxyz(2); 1 ; 1], ...
ctr * [dimxyz(1);dimxyz(2); 1 ; 1], ...
ctr * [ 1 ; 1 ;dimxyz(3); 1], ...
ctr * [dimxyz(1); 1 ;dimxyz(3); 1], ...
ctr * [ 1 ;dimxyz(2);dimxyz(3); 1], ...
ctr * [dimxyz(1);dimxyz(2);dimxyz(3); 1]]';
end
[xd{1:2}] = max(abs(ctr(1:3, 2)));
[yd{1:2}] = max(abs(ctr(1:3, 3)));
[zd{1:2}] = max(abs(ctr(1:3, 1)));
ao = [xd{2}, yd{2}, zd{2}];
ons = floor(min(ofmc(:, ao)) + 1e-2);
offs = ceil(max(ofmc(:, ao)) - 1e-2);
bbox = [ons; offs - 1];
cbox = bbox;
rcnv = cfr.IsRadiological;
otherwise
error('BAD_FILETYPE');
end
catch
error( ...
'BVQXfile:InternalError', ...
'BoundingBox is not a valid method of type %s.', ...
upper(ft) ...
);
end
% generate output struct
bbox = struct( ...
'BBox', bbox, ...
'CBox', cbox, ...
'DimXYZ', dimxyz, ...
'FCube', fc, ...
'RadCnv', rcnv, ...
'ResXYZ', resxyz);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -