function plot_elementstype(md,options_structure,width,i);
%PLOT_ELEMENTSTYPE - plot elements type
%
%   Usage:
%      plot_elementstype(md,options_structure,width,i);
%
%   See also: PLOTMODEL

%process data and model
[x y z elements is2d]=processmesh(md,options_structure);
[data1 isongrid]=processdata(md,md.elements_type(:,1),options_structure);
[data2 isongrid]=processdata(md,md.elements_type(:,2),options_structure);
data=[data1 data2];

%edgecolor?
if ~isnan(options_structure.edgecolor),
	edgecolor=options_structure.edgecolor;
else
	edgecolor='none';
end

%plot
subplot(width,width,i);

if is2d
	%Hutter elements
	posH=find(data(:,1)==hutterenum);
	A=elements(posH,1); B=elements(posH,2); C=elements(posH,3); 
	p1=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData',hutterenum,'FaceColor','flat','EdgeColor',edgecolor);
	%MacAyeal element
	posH=find(data(:,1)==macayealenum);
	A=elements(posH,1); B=elements(posH,2); C=elements(posH,3); 
	p2=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData',macayealenum,'FaceColor','flat','EdgeColor',edgecolor);
	%Pattyn element
	posH=find(data(:,1)==pattynenum);
	A=elements(posH,1); B=elements(posH,2); C=elements(posH,3); 
	p3=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData',pattynenum,'FaceColor','flat','EdgeColor',edgecolor);
	%Stokes elements
	alpha=0.35;
	posS=find(data(:,2)==stokesenum);
	if ~isempty(posS)
		A=elements(posS,1); B=elements(posS,2); C=elements(posS,3);
	%	p4=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData',stokesenum,'FaceColor','flat','EdgeColor',edgecolor,'EdgeAlpha',alpha,'FaceAlpha',alpha);
	%	legend([p1 p2 p3 p4],'Hutter''s elements','MacAyeal''s elements','Pattyn''s elements','Stokes''s elements');
	else
		legend([p1 p2 p3],'Hutter''s elements','MacAyeal''s elements','Pattyn''s elements');
	end
else
	%Hutter elements
	posH=find(data(:,1)==hutterenum);
	A=elements(posH,1); B=elements(posH,2); C=elements(posH,3); D=elements(posH,4); E=elements(posH,5); F=elements(posH,6);
	p1=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData', hutterenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [D E F], 'Vertices', [x y z],'CData', hutterenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [A B E D], 'Vertices', [x y z],'CData', hutterenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [B E F C ], 'Vertices', [x y z],'CData', hutterenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [C A D F ], 'Vertices', [x y z],'CData', hutterenum,'FaceColor','flat','EdgeColor',edgecolor);
	%MacAyeal elements
	posM=find(data(:,1)==macayealenum);
	A=elements(posM,1); B=elements(posM,2); C=elements(posM,3); D=elements(posM,4); E=elements(posM,5); F=elements(posM,6);
	p2=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData', macayealenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [D E F], 'Vertices', [x y z],'CData', macayealenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [A B E D], 'Vertices', [x y z],'CData', macayealenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [B E F C ], 'Vertices', [x y z],'CData', macayealenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [C A D F ], 'Vertices', [x y z],'CData', macayealenum,'FaceColor','flat','EdgeColor',edgecolor);
	%Pattyn elements
	posP=find(data(:,1)==pattynenum);
	A=elements(posP,1); B=elements(posP,2); C=elements(posP,3); D=elements(posP,4); E=elements(posP,5); F=elements(posP,6);
	p3=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData', pattynenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [D E F], 'Vertices', [x y z],'CData', pattynenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [A B E D], 'Vertices', [x y z],'CData', pattynenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [B E F C ], 'Vertices', [x y z],'CData', pattynenum,'FaceColor','flat','EdgeColor',edgecolor);
	patch( 'Faces', [C A D F ], 'Vertices', [x y z],'CData', pattynenum,'FaceColor','flat','EdgeColor',edgecolor);
	%Stokes elements
	alpha=0.35;
	posS=find(data(:,2)==stokesenum);
	if ~isempty(posS)
		A=elements(posS,1); B=elements(posS,2); C=elements(posS,3); D=elements(posS,4); E=elements(posS,5); F=elements(posS,6);
	%	p4=patch( 'Faces', [A B C], 'Vertices', [x y z],'CData', stokesenum,'FaceColor','flat','EdgeColor',edgecolor,'EdgeAlpha',alpha,'FaceAlpha',alpha);
	%	patch( 'Faces', [D E F], 'Vertices', [x y z],'CData', stokesenum,'FaceColor','flat','EdgeColor',edgecolor,'EdgeAlpha',alpha,'FaceAlpha',alpha);
	%	patch( 'Faces', [A B E D], 'Vertices', [x y z],'CData', stokesenum,'FaceColor','flat','EdgeColor',edgecolor,'EdgeAlpha',alpha,'FaceAlpha',alpha);
	%	patch( 'Faces', [B E F C ], 'Vertices', [x y z],'CData', stokesenum,'FaceColor','flat','EdgeColor',edgecolor,'EdgeAlpha',alpha,'FaceAlpha',alpha);
	%	patch( 'Faces', [C A D F ], 'Vertices', [x y z],'CData', stokesenum,'FaceColor','flat','EdgeColor',edgecolor,'EdgeAlpha',alpha,'FaceAlpha',alpha);
	%	legend([p1 p2 p3 p4],'Hutter''s elements','MacAyeal''s elements','Pattyn''s elements','Stokes''s elements');
	else
		legend([p1 p2 p3],'Hutter''s elements','MacAyeal''s elements','Pattyn''s elements');
	end
end

%apply options
if isnan(options_structure.title)
	options_structure.title='Elements type';
end 
if isnan(options_structure.colorbar)
	options_structure.colorbar=0;
end
applyoptions(md,[],options_structure);
