0001 function varargout = concatenateMeshes(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 assert(~isempty(varargin))
0022
0023 if isstruct(varargin{1})
0024 VF_fields = {'vertices','faces'};
0025
0026 errorStructFields=['If the first input argument is a struct '...
0027 'with the fields vertices and faces the additonal ' ...
0028 'arguments must have the same format'];
0029
0030 assert(all(cellfun(@isstruct, varargin)), errorStructFields)
0031
0032 assert(all(cellfun(@(x) all(ismember(fieldnames(x), ...
0033 VF_fields)), varargin)), errorStructFields)
0034
0035 if length(varargin)==1
0036 errorArgAndStructLength = ['If the input is only one struct ' ...
0037 'it has to contain more than one mesh.'];
0038 assert(length(varargin{1})>1, ...
0039 errorArgAndStructLength)
0040 end
0041
0042
0043 varargin = cellfun(@(x) orderfields(x, VF_fields),varargin, 'UniformOutput',0);
0044
0045
0046 varargin = ...
0047 cellfun(@struct2cell, varargin, 'UniformOutput', false);
0048 varargin = cellfun(@squeeze, varargin, 'UniformOutput',0);
0049 varargin = reshape([varargin{:}],[],1)';
0050 end
0051
0052 NoA = length(varargin);
0053 assert(mod(NoA,2)==0);
0054
0055 cellfun(@(x) validateattributes(x, {'numeric'},...
0056 {'size',[NaN,3],'finite'}), varargin(1:2:end))
0057 cellfun(@(x) validateattributes(x, {'numeric'},...
0058 {'integer'}), varargin(2:2:end))
0059
0060 errorFacesRows='The faces of all meshes must have the same number of columns';
0061 assert(numel(unique(cellfun(@(x) size(x,2), varargin(2:2:end))))==1, errorFacesRows)
0062
0063
0064
0065 v=[];
0066 f=[];
0067 for m = 1:NoA/2
0068 vm = varargin{2*m-1};
0069 fm = varargin{2*m};
0070 f = [f; fm+size(v,1)];
0071 v = [v; vm];
0072 end
0073
0074
0075
0076 [v, f] = trimMesh(v, f);
0077
0078 switch nargout
0079 case 1
0080 mesh.vertices=v;
0081 mesh.faces=f;
0082 varargout{1}=mesh;
0083 case 2
0084 varargout{1}=v;
0085 varargout{2}=f;
0086 end
0087