function vec=PatchToVec(Patch)
%PATCHTOVEC - converts a patch to a vector by averaging over each vertex
%
%   Usage:
%      vec=PatchToVec(Patch)

%if the patch is P0: we have element values, return an element vector
switch(size(Patch.value,2)),
	case 1,
		vec(Patch.element)=Patch.value;
	case 3,
		connectivity=sparse(Patch.index(:),1,1);
		value       =sparse(Patch.index(:),1,Patch.value(:));
		vec=full(value./connectivity);
	case 6,
		connectivity=sparse(Patch.index(:),1,1);
		value       =sparse(Patch.index(:),1,Patch.value(:));
		vec=full(value./connectivity);
	otherwise,
		error('interpolation not supported yet');
	end
