%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% tabla çizim fonksiyonu, kendisine gönderilen 6 nokta için, yükseklik 
%değerine göre  tabla çizimi yapar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [p_handle] = tabla_cizimi_genel2( Points ,  yukseklik ,color,  p_handles )
%nargin=2 
if nargin < 4 ,     p_handles=0;   end
if nargin < 3 , color = [0.8,0.3,0.3]; end

%check for points that contains NaN and dont draw this .. 
%NaN must be on all element of a row
column1 = find(~isnan(Points(:,1)));
column2 = find(~isnan(Points(:,2)));
column3 = find(~isnan(Points(:,3)));

if length(column1)~=length(column2)
    error('NaN problem on platform data, please check that NaN must be all element of a row');
elseif length(column1)~=length(column3)
    error('NaN problem on platform data, please check that NaN must be all element of a row');
elseif length(column2)~=length(column3)
    error('NaN problem on platform data, please check that NaN must be all element of a row');
end

% all indices of Point that not contain NaN = column1
% only draw for this indices = column1

point_number = 2;

vertex = [ Points(1,:); Points(2,:); Points(3,:);
           Points(1,:)-[0,0,yukseklik]; Points(2,:)-[0,0,yukseklik]; Points(3,:)-[0,0,yukseklik];
         ];
   
faces = [ 1 2 3 1 ;
          1 4 6 3 ;
          3 2 5 6 ;
          2 5 4 1 ;
          4 5 6 4;
          ];
          
p_handle = patch('vertices',vertex,...
                 'faces',faces,...
                 'facecolor',color);     

             
vertex = [ Points(1,:); Points(4,:); Points(5,:);
           Points(1,:)-[0,0,yukseklik]; Points(4,:)-[0,0,yukseklik]; Points(5,:)-[0,0,yukseklik];
         ];
p_handle = patch('vertices',vertex,...
                 'faces',faces,...
                 'facecolor',color);     

             
vertex = [ Points(1,:); Points(6,:); Points(7,:);
           Points(1,:)-[0,0,yukseklik]; Points(6,:)-[0,0,yukseklik]; Points(7,:)-[0,0,yukseklik];
         ];
p_handle = patch('vertices',vertex,...
                 'faces',faces,...
                 'facecolor',color);     
     
             
             
% 
% if point_number>3
%     faces = [ 1:point_number ; ] ;
%     for i=1:1:point_number-1    
%         faces = [ faces; i  i+1 i+point_number+1  i+point_number  ones(1,point_number-4)*NaN ];
%     end    
%     faces = [ faces ; point_number+1:2*point_number; 1 point_number 2*point_number point_number+1 ones(1,point_number-4)*NaN ; ];
%     
% elseif point_number==3
%     faces = [ 1:point_number ones(1,4-point_number)*NaN ; ] ;
%     for i=1:1:point_number-1    
%         faces = [ faces; i  i+1 i+point_number+1  i+point_number  ones(1,point_number-4)*NaN ];
%     end   
%     faces = [ faces ; point_number+1:2*point_number NaN; 1 point_number 2*point_number point_number+1 ; ]           ;
% else
%     error('myApp:argChk', 'platform en az üç nokta içermelidir')
% end
%  
% if nargin == 3 
%         
%     p_handle = patch('vertices',vertex,...
%                  'faces',faces,...
%                  'facecolor',color);
% else 
%     
%     set(p_handles,'vertices',vertex);
%     p_handle = p_handles;
% 
% end      