//to display a metamer according to the topological parameters


p=1;

g=gcf();
//g=scf();
g.figure_name='Growth Unit';
g.visible='off';
drawlater();


     InternodeH =  sqrt(a_bI(p)) * VI(p) ^ ((1 + a_aI(p)) / 2);  //if a_aI(p)=-1, I_H have nothing to do with qi
     InternodeS = sqrt(1 / a_bI(p)) * VI(p) ^ ((1 - a_aI(p)) / 2);
     
     D=[InternodeH InternodeS];Vo=eye(3,3);C=Color_I(1,:);Oo=[0 0 0];
     

      N=8;// number of points for the polygon
      t=linspace(0,2*%pi,N);//discretize the angle
      bx=D(2)/2*cos(t); by=D(2)/2*sin(t); //base points coordinates, vectors
      bz1=zeros(1,N); //bottom
      bz2=D(1)*ones(1,N);//top
      points1=[bx ;by;bz1 ];//points on the bottom
      points2=[bx; by;bz2 ;];//points on the top   
      points=[points1 points2];
      XI=[]; YI=[]; ZI=[]; CI=[];

      
      [P,nbfaces,Faces] = Draw_read_organ(Smb_L);
      LeafS=VB(p)/Th_B(p);
      L=sqrt(LeafS);

sumi=0;//number of metamers
for b=p:maxp
  for i=1:Nu_I(p,b)    
    sumi=sumi+1;
    //1. Internode                               
      
      [XI, YI, ZI, CI]=Draw_Internode(XI, YI, ZI, CI,points,Oo,Vo,C);   
      Oo=Oo+[0 0 InternodeH];
      plot3d(XI,YI,list(ZI,CI)); 
      h=get("hdl");
      h.hiddencolor=-CI;      

    //2.leaves
    if Nu_O(1,p,b)>0 then
      //O=[0,0,InternodeH];
      O=Oo;
      V=eye(3,3); C=Color_B(1,:);

      //leaf insertion angle
      Vx=[sin(Ang_O(1,p,b)) 0 cos(Ang_O(1,p,b)) ;0 1 0;cos(Ang_O(1,p,b)) 0 -sin(Ang_O(1,p,b))];  
      
      for i=1:Nu_O(1,p,b)
        //phylotaxxy angle
        w=i*Ang_Ph(p);
        Vz=[cos(w) -sin(w) 0;sin(w) cos(w) 0; 0 0 1];     
        V=Vz*Vx;
        [X,Y,Z,CP]=Draw_SMB(P,nbfaces,Faces,L,O,V,C);     
    
        for i=1:length(X)
          if size(X(i),2)>1 then //a single facet has problem of 'monotonous'
             plot3d(X(i),Y(i),list(Z(i),CP(i)));
             h=get("hdl");
              h.hiddencolor=-CP(i);    
          end
        end        
      end
    end
end
end
//3.female flowers


//4. male flowers

//e.color_mode=-e.color_mode;      




a=gca(); //get current axes
a.rotation_angles=[90,90]; 

g.visible='on';
drawnow();
