function Result=rest_reSample3D(A3DBrain, ANewDimension)
%Resample 3D matrix, such as in REST mask resampling operation
%-----------------------------------------------------------
%	Copyright(c) 2007~2010
%	State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
%	Written by Xiao-Wei Song 
%	http://resting-fmri.sourceforge.net
% 	<a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
%	Version=1.0
%	Release=20080801
%-----------------------------------------------------------


[dim1,dim2,dim3]=size(A3DBrain);
theFactor = ANewDimension./size(A3DBrain);

theInterpolant={'cubic','cubic','cubic'};
thePadMethod='fill';

theResampleStruct = makeresampler(theInterpolant, thePadMethod);
theTransFormStruct= maketform('affine', [theFactor(1) 0 0 ; 0 theFactor(2) 0; 0 0 theFactor(3);0 0 0]);

Result = tformarray(A3DBrain,theTransFormStruct,theResampleStruct,[1 2 3],[1 2 3],ANewDimension,[],[]); 
