% Resampling matrix: matrix vector multiplication
%
% (c) by Hannes Nickisch & Alexander Loktyushin, 
%                               MPI for Biological Cybernetics, 2011 February 11

function y = mvm(A,x,ctransp)
  if any(strfind(lower(A.type),'mex'))
    % method needs to contain {lin, cub, *} to match {linear, cubic, nearest}
    if any(strfind(lower(A.method),'lin'))
      mode = 1;
    elseif any(strfind(lower(A.method),'cub'))
      mode = 2;
    else
      mode = 0;
    end
    y = resample_mex(A.x(:),x(:),A.imsz,ctransp,A.di,mode);
  else
    if A.di
      if numel(A.dW{A.di})==0                                       % precompute
        A.dW{A.di} = resample_mat(A.imsz,A.x,A.method,A.di);
      end
      if ctransp, y = A.dW{A.di}'*x(:); else y = A.dW{A.di}*x(:); end
    else
      if ctransp, y = A.W'*x(:); 
      else 
          y = A.W *x(:); 
      end
    end
  end