Plo3d.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library
00003  *    Copyright (C) 1998-2001 Enpc/Jean-Philippe Chancelier
00004  *    jpc@cermics.enpc.fr 
00005  --------------------------------------------------------------------------*/
00006 
00007 #include <string.h> /* in case of dbmalloc use */
00008 #include <math.h>
00009 #include <stdio.h>
00010 #include "math_graphics.h"
00011 #include "PloEch.h"
00012 #include "GetProperty.h"
00013 #include "SetProperty.h"
00014 #include "DrawObjects.h"
00015 #include "Xcall1.h"
00016 #include "Plo3d.h"
00017 #include "axesScale.h"
00018 #include "BasicAlgos.h"
00019 #include "sciprint.h"
00020 #include "Format.h"
00021 #include "periScreen.h"
00022 #include "CurrentObjectsManagement.h"
00023 
00024 #include "MALLOC.h" /* MALLOC */
00025 
00026 void wininfo  __PARAMS((char *fmt,...)); 
00027 
00028 extern double C2F(dsort)();
00029 extern char GetDriver(void);
00030 extern int Check3DPlots(char *, integer *);
00031 extern int scilab_shade(integer *polyx, integer *polyy, integer *fill, integer polysize, integer flag);
00032 
00034 #define PGEOX(x1,y1,z1) inint(xx1= Cscale.Wscx1*(TRX(x1,y1,z1)-Cscale.frect[0]) +Cscale.Wxofset1);
00035 #define PGEOY(x1,y1,z1) inint(yy1= Cscale.Wscy1*(-TRY(x1,y1,z1)+Cscale.frect[3])+Cscale.Wyofset1);
00036 
00037 static void dbox __PARAMS((void));
00038 
00039 /*-------------------------------------------------------------------
00040  * box3d 
00041  *-------------------------------------------------------------------*/
00042 
00043 int C2F(box3d)(double *xbox, double *ybox, double *zbox)
00044 {  
00045  
00046   static integer InsideU[4],InsideD[4],flag[]={1,1,3};
00047   static integer ixbox[4],iybox[4], n=2, m=1;
00048   char * legends = NULL;
00049   sciPointObj * psubwin = NULL;
00050   sciSubWindow * ppsubwin =  NULL;
00051   
00052   char * legx = NULL;
00053   char * legy = NULL;
00054   char * legz = NULL;
00060   psubwin = sciGetCurrentSubWin();
00061   ppsubwin = pSUBWIN_FEATURE (psubwin);
00062 
00063   legx = getStrMatElement( sciGetText(ppsubwin->mon_x_label), 0, 0 ) ;
00064   legy = getStrMatElement( sciGetText(ppsubwin->mon_y_label), 0, 0 ) ;
00065   legz = getStrMatElement( sciGetText(ppsubwin->mon_z_label), 0, 0 ) ;
00066 
00067   if ((legends = MALLOC ((strlen(legx)+
00068     strlen(legy)+
00069     strlen(legz)+
00070     7)*sizeof (char))) == NULL)
00071     sciprint("box3d : No more Place to store legends (3D labels)\n");
00072 
00073   if(legx == NULL)
00074     strcpy(legends,"");
00075   else
00076     strcpy(legends,legx);
00077 
00078   strcat(legends,"@"); 
00079 
00080   if(legy == NULL)
00081     strcat(legends,"");
00082   else
00083     strcat(legends,legy);
00084 
00085   strcat(legends,"@"); 
00086 
00087   if(legz == NULL)
00088     strcat(legends,"");
00089   else
00090     strcat(legends,legz);
00091 
00092   Convex_Box(xbox,ybox,InsideU,InsideD,legends,flag,Cscale.bbox1);
00093   FREE(legends); legends = NULL;
00094 
00095 
00096   C2F (dr) ("xset","thickness",&m,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);    
00097   if (zbox[InsideU[0]] > zbox[InsideD[0]])
00098     DrawAxis(xbox,ybox,InsideU,2);
00099   else 
00100     DrawAxis(xbox,ybox,InsideD,2);    
00101   if (zbox[InsideU[0]] > zbox[InsideD[0]])
00102     DrawAxis(xbox,ybox,InsideD,2);
00103   else 
00104     DrawAxis(xbox,ybox,InsideU,2);
00105 
00106   ixbox[0]=XScale(xbox[0]);ixbox[1]=XScale(xbox[2]);
00107   ixbox[2]=XScale(xbox[1]);ixbox[3]=XScale(xbox[3]);
00108   iybox[0]=YScale(ybox[0]); iybox[1]=YScale(ybox[2]);
00109   iybox[2]=YScale(ybox[1]); iybox[3]=YScale(ybox[3]);
00110   C2F(dr)("xpolys","v",ixbox,iybox,&n,&m,&n,PI0,PD0,PD0,PD0,PD0,0L,0L);  
00111   C2F(dr)("xpolys","v",ixbox+2,iybox+2,&n,&m,&n,PI0,PD0,PD0,PD0,PD0,0L,0L); 
00112 
00113 
00114 
00115   return(0);
00116 }
00117 
00118 
00119 /*-------------------------------------------------------------------
00120  * functions for 3D scales 
00121  *-------------------------------------------------------------------*/
00122 
00123 /* 
00124  * if flag==1,2,3  m and bbox and Cscale are  recomputed  
00125  * if flag==0      we only change m without changing scales 
00126  */
00127 
00128 void SetEch3d1(double *xbox, double *ybox, double *zbox, double *bbox, double *teta, double *alpha, integer flag)
00129 {
00130   double xmmin,ymmax,xmmax,ymmin,FRect[4],WRect[4],ARect[4];
00131   integer ib;
00132   static integer aaint[]={2,10,2,10};
00133   int verbose=0,wdim[2],narg_;
00134   char logf_[2];
00135   double R,xo,yo,zo,dx,dy,dz,hx,hy,hx1,hy1,Teta,Alpha;
00136   integer wmax,hmax;
00137   static double cost=0.5,sint=0.5,cosa=0.5,sina=0.5;
00138   Teta=*teta;
00139   Alpha=*alpha;
00140   /*  if (flag==0) {
00141       Alpha=Cscale.alpha;
00142       Teta=Cscale.theta;
00143       }
00144       else {
00145       Cscale.alpha = Alpha;
00146       Cscale.theta = Teta;
00147       }*/
00148   Cscale.alpha = Alpha;
00149   Cscale.theta = Teta;
00150   cost=cos((Teta)*M_PI/180.0);
00151   sint=sin((Teta)*M_PI/180.0);
00152   cosa=cos((Alpha)*M_PI/180.0);
00153   sina=sin((Alpha)*M_PI/180.0);
00154   Cscale.m[0][0]= -sint    ;    Cscale.m[0][1]= cost      ;    Cscale.m[0][2]= 0;
00155   Cscale.m[1][0]= -cost*cosa;   Cscale.m[1][1]= -sint*cosa;    Cscale.m[1][2]= sina;
00156   Cscale.m[2][0]=  cost*sina;   Cscale.m[2][1]= sint*sina;     Cscale.m[2][2]= cosa;
00157   /* Coordonn\'ees apr\`es transformation g\'eometrique de la
00158    * boite qui entoure le plot3d                            
00159    * le plan de projection est defini par x et y            
00160    */
00161   for (ib=0;ib<6 ;ib++) 
00162     { 
00163       if (flag==0) 
00164         bbox[ib]=Cscale.bbox1[ib];
00165       else 
00166         Cscale.bbox1[ib]=bbox[ib];
00167     }
00168   xbox[0]=TRX(bbox[0],bbox[2],bbox[4]);
00169   ybox[0]=TRY(bbox[0],bbox[2],bbox[4]);
00170   zbox[0]=TRZ(bbox[0],bbox[2],bbox[4]);
00171   xbox[1]=TRX(bbox[0],bbox[3],bbox[4]);
00172   ybox[1]=TRY(bbox[0],bbox[3],bbox[4]);
00173   zbox[1]=TRZ(bbox[0],bbox[3],bbox[4]);
00174   xbox[2]=TRX(bbox[1],bbox[3],bbox[4]);
00175   ybox[2]=TRY(bbox[1],bbox[3],bbox[4]);
00176   zbox[2]=TRZ(bbox[1],bbox[3],bbox[4]);
00177   xbox[3]=TRX(bbox[1],bbox[2],bbox[4]);
00178   ybox[3]=TRY(bbox[1],bbox[2],bbox[4]);
00179   zbox[3]=TRZ(bbox[1],bbox[2],bbox[4]);
00180   xbox[4]=TRX(bbox[0],bbox[2],bbox[5]);
00181   ybox[4]=TRY(bbox[0],bbox[2],bbox[5]);
00182   zbox[4]=TRZ(bbox[0],bbox[2],bbox[5]);
00183   xbox[5]=TRX(bbox[0],bbox[3],bbox[5]);
00184   ybox[5]=TRY(bbox[0],bbox[3],bbox[5]);
00185   zbox[5]=TRZ(bbox[0],bbox[3],bbox[5]);
00186   xbox[6]=TRX(bbox[1],bbox[3],bbox[5]);
00187   ybox[6]=TRY(bbox[1],bbox[3],bbox[5]);
00188   zbox[6]=TRZ(bbox[1],bbox[3],bbox[5]);
00189   xbox[7]=TRX(bbox[1],bbox[2],bbox[5]);
00190   ybox[7]=TRY(bbox[1],bbox[2],bbox[5]);
00191   zbox[7]=TRZ(bbox[1],bbox[2],bbox[5]);
00193   if ( flag == 1 || flag == 3 )
00194     {
00195       xmmin=  (double) Mini(xbox,8L);xmmax= (double) Maxi(xbox,8L);
00196       ymmax=  (double) - Mini(ybox,8L);
00197       ymmin=  (double) - Maxi(ybox,8L);
00198     }
00199   /* code added by es: isoview scaling */
00200   if ( flag == 2 || flag == 3 )
00201     {
00202       /* get current window size */
00203       C2F(dr)("xget","wdim",&verbose,wdim,&narg_, PI0,PI0,PI0,
00204               PD0,PD0,PD0,PD0,0L,0L);
00205       getscale2d(WRect,FRect,logf_,ARect);
00206       wmax=linint((double)wdim[0] * WRect[2]);
00207       hmax=linint((double)wdim[1] * WRect[3]); 
00208     }
00209   if ( flag == 2 )
00210     {
00211       /* radius and center of the sphere circumscribing the box */
00212       dx=bbox[1]-bbox[0]; dy=bbox[3]-bbox[2]; dz=bbox[5]-bbox[4];
00213       R= (double) sqrt(dx*dx + dy*dy + dz*dz)/2;
00214       xo= (double) (xbox[0]+xbox[6])/2 ;
00215       yo= (double) (ybox[0]+ybox[6])/2 ;
00216       zo= (double) (zbox[0]+zbox[6])/2 ;
00217       xmmin=  (double) xo - R ;
00218       xmmax=  (double) xo + R ;
00219       ymmax=  (double) -yo + R ;
00220       ymmin=  (double) -yo - R ;
00221     }
00222   if (flag==2 || flag==3)
00223     {
00224       /* adjust limits (code adapted from Plo2d.c & Stephane's patch) */
00225       hx=xmmax-xmmin;
00226       hy=ymmax-ymmin;
00227       if ( hx/(double)wmax  < hy/(double)hmax ) 
00228         {
00229           hx1=wmax*hy/hmax;
00230           xmmin=xmmin-(hx1-hx)/2.0;
00231           xmmax=xmmax+(hx1-hx)/2.0;
00232         }
00233       else 
00234         {
00235           hy1=hmax*hx/wmax;
00236           ymmin=ymmin-(hy1-hy)/2.0;
00237           ymmax=ymmax+(hy1-hy)/2.0;
00238         }
00239     }
00240   if (flag !=0 )
00241     {
00242       FRect[0]=xmmin;FRect[1]= -ymmax;FRect[2]=xmmax;FRect[3]= -ymmin;
00243       set_scale("tftttf",NULL,FRect,aaint,"nn",NULL);
00244       Cscale.metric3d=flag; /* the metric mode is stored into the
00245                              * List of Scales */
00246     }
00247   /* end of code added by es */
00248 }
00249 
00250 /* renvoit les indices des points voisins de ind1 sur la face haute 
00251 de la boite  */
00252 
00253 void UpNext(integer ind1, integer *ind2, integer *ind3)
00254 {
00255   *ind2 = ind1+1;
00256   *ind3 = ind1-1;
00257   if (*ind2 == 8) *ind2 = 4;
00258   if (*ind3 == 3) *ind3 = 7;
00259 }
00260 
00261 void DownNext(integer ind1, integer *ind2, integer *ind3)
00262 {
00263   *ind2 = ind1+1;
00264   *ind3 = ind1-1;
00265   if (*ind2 == 4) *ind2 = 0;
00266   if (*ind3 == -1) *ind3 = 3;
00267 }
00268 
00269 /*---------------------------------------------------------------------
00270  *Trace l'enveloppe convexe de la boite contenant le dessin 
00271  * et renvoit dans InsideU et InsideD les indices des points dans xbox et ybox
00272  * qui sont sur les 2 tri\`edres a l'interieur de l'enveloppe convexe
00273  *---------------------------------------------------------------------*/
00274 
00275 void Convex_Box(double *xbox, double *ybox, integer *InsideU, integer *InsideD, char *legend, integer *flag, double *bbox)
00276 {
00277   double xmaxi;
00278   integer ixbox[8],iybox[8];
00279   integer xind[8];
00280   integer ind2,ind3,ind;
00281   integer p,n,dvect[1],dash[6];
00282   integer verbose=0,narg_,pat;
00283   integer i,j;
00290   /*      4 ----- 5        */
00291   /*       /    /|         */
00292   /*     7----6  |         */
00293   /*      | 0 | / 1        */
00294   /*     3----- 2          */
00298   xmaxi=((double) Maxi(xbox,8L));
00299   ind= -1;
00300   for (i =0 ; i < 8 ; i++)
00301     {
00302       MaxiInd(xbox,8L,&ind,xmaxi);
00303       if ( ind > 3)
00304         {
00305           xind[0]=ind;
00306           break;
00307         }
00308     }
00309   if (ind < 0 || ind > 8) 
00310     {
00311       sciprint("xind out of bounds");
00312       xind[0]=0;
00313     }
00314   UpNext(xind[0],&ind2,&ind3);
00315   if (ybox[ind2] > ybox[ind3]) 
00316     {
00317       xind[1]=ind2;InsideU[0]=ind3;
00318     }
00319   else 
00320     {
00321       xind[1]=ind3;InsideU[0]=ind2;
00322     }
00323   UpNext(ind2,&ind2,&ind3); InsideU[1]=xind[0];
00324   InsideU[2]=ind2; InsideU[3]=InsideU[0]-4;
00325   xind[2]=ind2;
00326   /* le pointeger en bas qui correspond */
00327   xind[3]=ind2-4;
00328   DownNext(xind[3],&ind2,&ind3);
00329   if (ybox[ind2] < ybox[ind3]) 
00330     {
00331       xind[4]=ind2;InsideD[0]=ind3;
00332     }
00333   else  
00334     {
00335       xind[4]=ind3;InsideD[0]=ind2;
00336     }
00337   DownNext(ind2,&ind2,&ind3);
00338   InsideD[1]=xind[3];
00339   InsideD[2]=ind2;
00340   InsideD[3]=InsideD[0]+4;
00341   xind[5]=ind2;
00342   for (i=0; i < 6 ; i++)
00343     {
00344       ixbox[i]=XScale(xbox[xind[i]]);
00345       iybox[i]=YScale(ybox[xind[i]]);
00346     }
00347   ixbox[6]=ixbox[0];iybox[6]=iybox[0];
00348   p=7,n=1;
00351   dvect[0]=2;       
00353   C2F(dr)("xget","line style",&verbose,dash,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00354   C2F(dr)("xset","line style",(j=1,&j),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00355   C2F (dr) ("xset","thickness",(j=1,&j),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);     
00356   if (flag[2]>=3){
00357     C2F(dr)("xpolys","v",ixbox,iybox,dvect,&n,&p
00358             ,PI0,PD0,PD0,PD0,PD0,0L,0L);
00359   }
00360   C2F(dr)("xget","pattern",&verbose,&pat,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00361   C2F(dr)("xset","pattern",dvect,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L); 
00362   if (flag[2]>=3)
00363     AxesStrings(flag[2],ixbox,iybox,xind,legend,bbox);
00364   C2F(dr)("xset","pattern",&pat,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00365   C2F(dr)("xset","line style",dash,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00366 
00367 }
00368 
00369 void C2F(TDdrawaxis)(double size, double FPval, double LPval, integer *nax, integer *FPoint, integer *LPoint, integer *Ticsdir)
00370 { 
00371   integer i;
00372   double dx,dy,ticsx,ticsy;
00373   dx= ((double) LPoint[0]-FPoint[0])/((double)nax[1]*nax[0]);
00374   dy= ((double) LPoint[1]-FPoint[1])/((double)nax[1]*nax[0]);
00375   if ( Ticsdir[0] == 0 && Ticsdir[1] == 0) 
00376   {
00377     ticsx= ticsy = 0;
00378   }
00379   else 
00380   {
00381     ticsx= ( Ticsdir[0])/
00382       sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1]);
00383     ticsy= ( Ticsdir[1])/
00384       sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1]);
00385   }
00386   for (i=0; i <= nax[1]*nax[0];i++)
00387   {       
00388     integer siz=2,x[2],y[2],iflag=0,style=0;
00389     x[0] =linint(FPoint[0]+ ((double)i)*dx );
00390     y[0] =linint(FPoint[1]+ ((double)i)*dy );
00391     x[1] =linint(x[0]+ ticsx*size);
00392     y[1] =linint(y[0]+ ticsy*size);
00393     C2F(dr)("xsegs","v",x,y,&siz,&style,&iflag,PI0,PD0,PD0,PD0,PD0,0L,0L);
00394   }
00395 }
00396 
00397 
00398 void TDAxis(integer flag, double FPval, double LPval, integer *nax, integer *FPoint, integer *LPoint, integer *Ticsdir)
00399 {
00400   char fornum[100];
00401   integer i,barlength;
00402   double xp, dx,dy,ticsx,ticsy,size;
00403   integer verbose=0,narg_,xz[2];
00404   C2F(dr)("xget","wdim",&verbose,xz,&narg_, PI0, PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00405   size = xz[0]>=xz[1] ? xz[1]/50.0 : xz[0]/50.0; 
00406   C2F(TDdrawaxis)(size,FPval,LPval,nax,FPoint,LPoint,Ticsdir) ;
00407   ChoixFormatE(fornum,Min(FPval,LPval),Max(LPval,FPval),
00408     Abs((LPval-FPval))/nax[1]);
00409   xp= FPval;
00410   barlength=inint(1.2*size);
00411   dx= ((double) LPoint[0]-FPoint[0])/((double)nax[1]);
00412   dy= ((double) LPoint[1]-FPoint[1])/((double)nax[1]);
00413   if ( Ticsdir[0] == 0 && Ticsdir[1] == 0) 
00414   {
00415     ticsx= ticsy = 0;
00416   }
00417   else 
00418   {
00419     ticsx= barlength*( Ticsdir[0])/
00420       sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1]);
00421     ticsy= barlength*( Ticsdir[1])/
00422       sqrt((double) Ticsdir[0]*Ticsdir[0]+Ticsdir[1]*Ticsdir[1]);
00423   }
00424   for (i=0; i <= nax[1];i++)
00425   { double angle=0.0;
00426   integer flag1=0;
00427   integer xx=0,yy=0, posi[2],rect[4];
00428   char foo[100];/*** JPC : must be cleared properly **/
00429   double lp;
00430   lp = xp + i*(LPval-FPval)/((double)nax[1]);
00431   sprintf(foo,fornum,lp);   
00432   C2F(dr)("xstringl",foo,&xx,&yy,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00433   posi[0]=inint(FPoint[0]+ i*dx + 2*ticsx );
00434   posi[1]=inint(FPoint[1]+ i*dy + 2*ticsy +rect[3]/2 );
00435   switch ( flag)
00436   {
00437   case 1: posi[0] -= rect[2];
00439     if ( i== nax[1]) posi[1] -= rect[3]/2;
00440     break;
00441   case 2: posi[0] -= rect[2];break;
00442   }
00443   C2F(dr)("xstring",foo,&(posi[0]),&(posi[1]),PI0,&flag1,PI0,PI0,&angle,PD0,PD0,PD0,0L,0L);
00444   } 
00445 }
00446 
00447 
00453 void AxesStrings(integer axflag, integer *ixbox, integer *iybox, integer *xind, char *legend, double *bbox)
00454 {
00455   integer verbose=0,narg_,xz[2];
00456   integer iof;
00457   char *loc = NULL;
00458   /*   char * buff = NULL; */
00459   char * legx = NULL;
00460   char * legy = NULL;
00461   char * legz = NULL;
00462   integer rect[4],flag=0,x,y;
00463   double ang=0.0;
00464 
00465   loc=(char *) MALLOC( (strlen(legend)+1)*sizeof(char));
00466   if ( loc == NULL)
00467     {
00468       sciprint("AxesString : No more Place to store Legends\n");
00469       return;
00470     }
00471   
00472   strcpy(loc,legend);
00473   /*   legx=strtok_r(loc,"@",&buff); */
00474   /*   legy=strtok_r(NULL,"@",&buff); */
00475   /*   legz=strtok_r(NULL,"@",&buff); */
00476  
00477   legx=strtok(loc,"@");
00478   legy=strtok(NULL,"@");
00479   legz=strtok(NULL,"@");
00480 
00482   C2F(dr)("xget","wdim",&verbose,xz,&narg_, PI0, PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00483   iof = (xz[0]+xz[1])/50;
00484 
00485   x = (integer) (ixbox[2]-(xz[0]+xz[1])/20) ;
00486   y = (integer) (0.5*iybox[3]+0.5*iybox[2]);
00487   /*** le z scaling ***/
00488   if ( axflag>=4)
00489     {
00490       double fx,fy,fz,lx,ly,lz;
00491       integer LPoint[2],FPoint[2],Ticsdir[2],xnax[2];
00492       xnax[0]=5;xnax[1]=2;
00493       FPoint[0]=ixbox[2];FPoint[1]=iybox[2];
00494       LPoint[0]=ixbox[3];LPoint[1]=iybox[3];
00495       Ticsdir[0]= -1;
00496       Ticsdir[1]=0;
00497       BBoxToval(&fx,&fy,&fz,xind[2],bbox);
00498       BBoxToval(&lx,&ly,&lz,xind[3],bbox);
00499       TDAxis(1L,fz,lz,xnax,FPoint,LPoint,Ticsdir);
00500     }
00501   if (legz != NULL)
00502     {
00503       C2F(dr)("xstringl",legz,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00504       C2F(dr)("xstring",legz,(x=x - rect[2],&x),&y,PI0,&flag
00505               ,PI0,PI0,&ang,PD0,PD0,PD0,0L,0L);
00506     }
00509   x=inint((ixbox[3]+ixbox[4])/2.0 -iof);
00510   y=inint((1/3.0)*iybox[3]+(2/3.0)*iybox[4]+(xz[0]+xz[1])/30);
00511 
00512   if ( xind[3]+xind[4] == 3)
00513     {
00514       if ( axflag>=4)
00515         {
00516           double fx,fy,fz,lx,ly,lz;
00517           integer LPoint[2],FPoint[2],Ticsdir[2],xnax[2];
00518           xnax[0]=5;xnax[1]=2;
00519           FPoint[0]=ixbox[3];FPoint[1]=iybox[3];
00520           LPoint[0]=ixbox[4];LPoint[1]=iybox[4];
00521           Ticsdir[0]=ixbox[4]-ixbox[5];
00522           Ticsdir[1]=iybox[4]-iybox[5];
00523           BBoxToval(&fx,&fy,&fz,xind[3],bbox);
00524           BBoxToval(&lx,&ly,&lz,xind[4],bbox);
00525           TDAxis(2L,fx,lx,xnax,FPoint,LPoint,Ticsdir);
00526         }
00527       if (legx != NULL)
00528         {
00529 
00530           C2F(dr)("xstringl",legx,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00531           C2F(dr)("xstring",legx,(x=x-rect[2],&x),&y,PI0,&flag
00532                   ,PI0,PI0,&ang,PD0,PD0,PD0,0L,0L);
00533         }
00534     }
00535   else 
00536     {
00537       if ( axflag>=4)
00538         {
00539           double fx,fy,fz,lx,ly,lz;
00540           integer LPoint[2],FPoint[2],Ticsdir[2],xnax[2];
00541           xnax[0]=5;xnax[1]=2;
00542           FPoint[0]=ixbox[3];FPoint[1]=iybox[3];
00543           LPoint[0]=ixbox[4];LPoint[1]=iybox[4];
00544           Ticsdir[0]=ixbox[4]-ixbox[5];
00545           Ticsdir[1]=iybox[4]-iybox[5];
00546           BBoxToval(&fx,&fy,&fz,xind[3],bbox);
00547           BBoxToval(&lx,&ly,&lz,xind[4],bbox);
00548           TDAxis(2L,fy,ly,xnax,FPoint,LPoint,Ticsdir);
00549         }
00550       if (legy != NULL)
00551         {
00552 
00553           C2F(dr)("xstringl",legy,&x,&y,rect,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00554           C2F(dr)("xstring",legy,(x=x-rect[2],&x),&y,PI0,&flag
00555                   ,PI0,PI0,&ang,PD0,PD0,PD0,0L,0L);
00556         }
00557     }
00560   x=inint((ixbox[4]+ixbox[5])/2+(xz[0]+xz[1])/30);
00561   y=inint(((2/3.0)*iybox[4]+(1/3.0)*iybox[5])+iof);
00562 
00563   if ( xind[4]+xind[5] == 3)
00564   {
00565       if ( axflag>=4)
00566         {
00567           double fx,fy,fz,lx,ly,lz;
00568           integer LPoint[2],FPoint[2],Ticsdir[2],xnax[2];
00569           xnax[0]=5;xnax[1]=2;
00570           FPoint[0]=ixbox[4];FPoint[1]=iybox[4];
00571           LPoint[0]=ixbox[5];LPoint[1]=iybox[5];
00572           Ticsdir[0]=ixbox[4]-ixbox[3];
00573           Ticsdir[1]=iybox[4]-iybox[3];
00574           BBoxToval(&fx,&fy,&fz,xind[4],bbox);
00575           BBoxToval(&lx,&ly,&lz,xind[5],bbox);
00576           TDAxis(3L,fx,lx,xnax,FPoint,LPoint,Ticsdir); 
00577         }
00578       if (legx != NULL) 
00579         {
00580           C2F(dr)("xstring",legx,&x,&y,PI0,&flag,PI0,PI0,&ang,PD0,PD0,PD0,0L,0L);
00581         }
00582     }
00583   else 
00584     {
00585       if ( axflag>=4)
00586         {
00587           double fx,fy,fz,lx,ly,lz;
00588           integer LPoint[2],FPoint[2],Ticsdir[2],xnax[2];
00589           xnax[0]=5;xnax[1]=2;
00590           FPoint[0]=ixbox[4];FPoint[1]=iybox[4];
00591           LPoint[0]=ixbox[5];LPoint[1]=iybox[5];
00592           Ticsdir[0]=ixbox[4]-ixbox[3];
00593           Ticsdir[1]=iybox[4]-iybox[3];
00594           BBoxToval(&fx,&fy,&fz,xind[4],bbox);
00595           BBoxToval(&lx,&ly,&lz,xind[5],bbox);
00596           TDAxis(3L,fy,ly,xnax,FPoint,LPoint,Ticsdir); 
00597         }
00598       if (legy != NULL) 
00599         {
00600           C2F(dr)("xstring",legy,&x,&y,PI0,&flag,PI0,PI0,&ang,PD0,PD0,PD0,0L,0L);
00601         }
00602     }  
00603   FREE(loc);
00604 }
00605 
00606 
00609 void BBoxToval(double *x, double *y, double *z, integer ind, double bbox[6] )
00610 {
00611   switch ( ind)
00612     {
00613     case 0:     *x=bbox[0],*y=bbox[2],*z=bbox[4];break;
00614     case 1:     *x=bbox[0],*y=bbox[3],*z=bbox[4];break;
00615     case 2:     *x=bbox[1],*y=bbox[3],*z=bbox[4];break;
00616     case 3:     *x=bbox[1],*y=bbox[2],*z=bbox[4];break;
00617     case 4:     *x=bbox[0],*y=bbox[2],*z=bbox[5];break;
00618     case 5:     *x=bbox[0],*y=bbox[3],*z=bbox[5];break;
00619     case 6:     *x=bbox[1],*y=bbox[3],*z=bbox[5];break;
00620     case 7:     *x=bbox[1],*y=bbox[2],*z=bbox[5];break;
00621     }
00622 }
00623 
00624 /*-------------------------------------
00625  *  interactive rotation of a 3d plot 
00626  *--------------------------------------*/
00627 
00629 static double theta,alpha;
00630 /* return 1 if figure has been close during rotation */
00631 int I3dRotation(void)
00632 {
00633   integer pixmode,alumode,verbose=0,narg_,ww;
00634   double xx,yy;
00635   double theta0,alpha0;
00636   static int one=1;
00637 
00638   static integer modes[]={1,0};/* for xgemouse only get mouse mouvement*/ 
00639   sciSons *psonstmp;
00640   sciPointObj *psubwin, *tmpsubwin;
00641   sciPointObj *pold = NULL;
00642   /*  sciPointObj *psurface; */
00643   integer xr, yr;
00644 
00645 
00646   integer ibutton,in,iwait=0,istr=0;
00647   integer verbose_=0,ww_;
00648   double x0,yy0,x,y,xl,yl ;
00649 
00650   C2F(dr1)("xget","window",&verbose,&ww,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00651 
00653   C2F(dr)("xget","pixmap",&verbose,&pixmode,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00654   C2F(dr)("xget","alufunction",&verbose,&alumode,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00655 
00656 
00657 #ifdef _MSC_VER
00658   SetWinhdc();
00659   SciMouseCapture();  
00660 #endif
00661   C2F(dr)("xclick","one",&ibutton,&xr,&yr,&iwait,&istr,PI0,PD0,PD0,PD0,PD0,0L,0L);
00662 #ifdef _MSC_VER
00663   ReleaseWinHdc();
00664   SciMouseRelease();
00665 #endif
00666   theta=Cscale.theta ;
00667   alpha=Cscale.alpha ;
00668   theta0=theta;
00669   alpha0=alpha;
00670 
00671   ibutton=-1;
00672   tmpsubwin = sciGetCurrentSubWin() ;   
00673   if ( pFIGURE_FEATURE(sciGetCurrentFigure())->rotstyle == 0)    
00674   {
00675     psubwin = CheckClickedSubwin(xr,yr);
00677     if( psubwin != NULL )
00678     {
00679       sciSubWindow * ppSubWin = pSUBWIN_FEATURE(psubwin) ;
00680       sciSetSelectedSubWin (psubwin);
00681 
00682       theta0 = ppSubWin-> theta; 
00683       alpha0 = ppSubWin-> alpha;
00684       ppSubWin->is3d = TRUE;
00685       Cscale.metric3d = (long)(ppSubWin->axes.flag[1]+1)/2; 
00686 
00687       /* Modif. HERE F.Leray 24.05.04 : we take advantage of update_specification_bounds and update_3dbounds previous call */
00688       /* brect variable should not exist any more.*/
00689       Cscale.bbox1[0] = ppSubWin->FRect[0]; 
00690       Cscale.bbox1[1] = ppSubWin->FRect[2];
00691       Cscale.bbox1[2] = ppSubWin->FRect[1];
00692       Cscale.bbox1[3] = ppSubWin->FRect[3];
00693       Cscale.bbox1[4] = ppSubWin->FRect[4];
00694       Cscale.bbox1[5] = ppSubWin->FRect[5];
00695 
00696       if( ppSubWin->cube_scaling )
00697       {
00698         Cscale.bbox1[0] =  0.; 
00699         Cscale.bbox1[1] =  1.;
00700         Cscale.bbox1[2] =  0.;
00701         Cscale.bbox1[3] =  1.;
00702         Cscale.bbox1[4] =  0.;
00703         Cscale.bbox1[5] =  1.;
00704       }
00705     }
00706     else
00707     {
00708       wininfo("No 3d object selected");
00709       return 0;
00710     }
00711   }
00712   else
00713   {                  
00714     psonstmp = sciGetLastSons (sciGetCurrentFigure());  
00715     while (psonstmp != (sciSons *) NULL)
00716     {  
00717       if(sciGetEntityType (psonstmp->pointobj) == SCI_SUBWIN) 
00718         break;   
00719       psonstmp = psonstmp->pnext;
00720     } 
00721     sciSetSelectedSubWin (psonstmp->pointobj);
00722   } 
00723   xx=1.0/Abs(Cscale.frect[0]-Cscale.frect[2]);
00724   yy=1.0/Abs(Cscale.frect[1]-Cscale.frect[3]);
00725 
00726   C2F(echelle2d)(&x0,&yy0,&xr,&yr,&one,&one,"i2f",3L);
00727   x0=(x0-Cscale.frect[0])*xx;
00728   yy0=(yy0-Cscale.frect[1])*yy;
00729   x=x0;y=yy0;
00730 
00731 #ifdef _MSC_VER
00732   SetWinhdc();
00733   SciMouseCapture();
00734 #endif
00735 
00736   if ( pixmode == 0 ) C2F(dr1)("xset","alufunction",(in=6,&in),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00737 
00738   while ( ibutton == -1 ) 
00739   {
00740     /* dessin d'un rectangle */
00741     theta= ((int)(theta0 - 180.0*(x-x0)) % 360);
00742     alpha= ((int)(alpha0 + 180.0*(y-yy0)) % 360);
00743     wininfo("alpha=%.1f,theta=%.1f",alpha,theta); 
00744     if ( pixmode == 1) C2F(dr1)("xset","wwpc",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00745     dbox();
00746     if ( pixmode == 1) C2F(dr1)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00747     C2F(dr1)("xgetmouse","one",&ibutton,&iwait,PI0,PI0,modes,PI0,&xl, &yl,PD0,PD0,0L,0L);
00748     if (ibutton==-100) return 1;/* window has been closed */
00749     /* effacement du rectangle */
00750     dbox();
00751     xx=1.0/Abs(Cscale.frect[0]-Cscale.frect[2]);
00752     yy=1.0/Abs(Cscale.frect[1]-Cscale.frect[3]);
00753     x=(xl-Cscale.frect[0])*xx;
00754     y=(yl-Cscale.frect[1])*yy;
00755   }
00756   if ( pixmode == 0) C2F(dr1)("xset","alufunction",(in=3,&in),PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00757   C2F(dr1)("xget","window",&verbose_,&ww_,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00758   C2F(dr1)("xset","alufunction",&alumode,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00759 #ifdef _MSC_VER
00760   ReleaseWinHdc();
00761   SciMouseRelease();
00762 #endif
00763 
00764   if (pFIGURE_FEATURE((sciPointObj *)sciGetCurrentFigure())->rotstyle == 0){
00765     pold = sciGetCurrentSubWin();
00766     sciSetSelectedSubWin(psubwin);
00767     Obj_RedrawNewAngle(psubwin,theta,alpha);
00768     sciSetSelectedSubWin(pold);
00769   }
00770   else
00771   { 
00772     psonstmp = sciGetSons (sciGetCurrentFigure());  
00773     while (psonstmp != (sciSons *) NULL)        
00774     {  
00775       if(sciGetEntityType (psonstmp->pointobj) == SCI_SUBWIN){
00776         pold = sciGetCurrentSubWin();
00777         sciSetSelectedSubWin(psonstmp->pointobj);
00778         Obj_RedrawNewAngle(psonstmp->pointobj,theta,alpha);
00779         sciSetSelectedSubWin(pold);
00780       }
00781       psonstmp = psonstmp->pnext;
00782     } 
00783   }
00784   sciRedrawFigure(); 
00785   wininfo("alpha=%.1f,theta=%.1f",alpha,theta); 
00786   sciSetSelectedSubWin (tmpsubwin);
00787   return 0;
00788 }
00789 
00790 /*
00791  * Win32, warning when using xor mode
00792  * colors are changed and black is turned to white
00793  * so we must use an other pattern than the black one
00794  * inside dbox
00795  */
00796 
00797 static void dbox(void)
00798 {
00799   double xbox[8],ybox[8],zbox[8];
00800 #ifdef _MSC_VER
00801   integer verbose_=0,pat,pat1=3,narg_,un=1;
00802   C2F(dr)("xget","pattern",&verbose_,&pat,&narg_,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00803   C2F(dr)("xset","pattern",&pat1,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00804   C2F (dr) ("xset", "line style",&un,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00805 #endif
00806   SetEch3d1(xbox,ybox,zbox,Cscale.bbox1,&theta,&alpha,Cscale.metric3d);
00807   C2F(box3d)(xbox,ybox,zbox);
00808 #ifdef _MSC_VER
00809   C2F(dr)("xset","pattern",&pat,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00810 #endif
00811 }
00812 
00813 /*---------------------------------------------------------------------------------
00814  *This function sorts the vertices such that the color value is in decreasing order
00815  *---------------------------------------------------------------------------------*/
00816 
00817 int  triangleSort(integer *polyxin, integer *polyyin, integer *fillin, integer *polyx, integer *polyy, integer *fill)
00818 { 
00819   integer tmp,k;
00820   for (k=0;k<3;k++) {polyx[k]=polyxin[k]; polyy[k]=polyyin[k]; fill[k]=Abs(fillin[k]);}
00821       
00822   if (fill[0]<fill[1]) {  
00823     tmp=fill[0]; fill[0]=fill[1]; fill[1]=tmp;
00824     tmp=polyx[0]; polyx[0]=polyx[1]; polyx[1]=tmp;
00825     tmp=polyy[0]; polyy[0]=polyy[1]; polyy[1]=tmp;
00826   }
00827   if (fill[0]<fill[2]) {  
00828     tmp=fill[0]; fill[0]=fill[2]; fill[2]=tmp;
00829     tmp=polyx[0]; polyx[0]=polyx[2]; polyx[2]=tmp;
00830     tmp=polyy[0]; polyy[0]=polyy[2]; polyy[2]=tmp;
00831   }
00832   if (fill[1]<fill[2]) {  
00833     tmp=fill[1]; fill[1]=fill[2]; fill[2]=tmp;
00834     tmp=polyx[1]; polyx[1]=polyx[2]; polyx[2]=tmp;
00835     tmp=polyy[1]; polyy[1]=polyy[2]; polyy[2]=tmp;
00836   }
00837   return 0;
00838 }
00839 
00840 
00841 /*-----------------------------------------------------------------------
00842  * This is the main shading function. When the polygone has 4 vertices, it
00843  * is splitted in two triangles and shade() is recursively called twice.
00844  * Author : mottelet 2000 
00845  * XXXX: remplacer les malloc par graphic_alloc pour uniformiser avec les autres 
00846  *       routines 
00847  *-----------------------------------------------------------------------*/
00848 
00849 int scilab_shade(integer *polyx, integer *polyy, integer *fill, integer polysize, integer flag)
00850 {
00851   integer px[5],py[5],fil[4],is[3],ie[3],n[3];
00852   integer npoly=1,k,col,cols,psize,i,s,e;
00853   integer polyxs[4],polyys[4],fills[4],*x[3],*y[3];
00854   double dx,dy;
00855 
00856   if (polysize == 3) { /* The triangle case */
00857  
00858     triangleSort(polyx,polyy,fill,polyxs,polyys,fills);
00859   
00860     is[0]=0; ie[0]=1;
00861     is[1]=1; ie[1]=2;
00862     is[2]=0; ie[2]=2;
00863      
00864     /* Computation of coordinates of elementary polygons for each side */
00865      
00866     for(i=0;i<3;i++) {
00867 
00868       s=is[i];
00869       e=ie[i];
00870       n[i]=fills[s]-fills[e];
00871 
00872       if (n[i]) {
00873         
00874         x[i]=(integer *)MALLOC((n[i]+2)*sizeof(integer));
00875         y[i]=(integer *)MALLOC((n[i]+2)*sizeof(integer)); 
00876         if (x[i]==NULL || y[i]==NULL) {
00877           sciprint("shade : MALLOC No more Place\n");
00878           return 0;
00879         }
00880                 
00881         dx=((double)(polyxs[e]-polyxs[s]))/(double)n[i];
00882         dy=((double)(polyys[e]-polyys[s]))/(double)n[i];
00883 
00884         x[i][0]=polyxs[s];
00885         y[i][0]=polyys[s];
00886            
00887         for(k=0;k<n[i];k++) {
00888           x[i][k+1]=linint((double)polyxs[s] + (0.5+k)*dx);
00889           y[i][k+1]=linint((double)polyys[s] + (0.5+k)*dy);
00890         }
00891            
00892         x[i][n[i]+1]=polyxs[e];
00893         y[i][n[i]+1]=polyys[e];
00894       }
00895     }
00896      
00897     /* Fill the whole triangle with color fill[1] if all colors are equal */
00898          
00899     if (!n[0] && !n[1]) {
00900 
00901       psize=3;
00902       col=fills[0];
00903       C2F(dr)("xliness","str",polyxs,polyys,(cols=-Abs(col),&cols),&npoly,&psize ,PI0,PD0,PD0,PD0,PD0,0L,0L);
00904       /*          return(0);*/
00905     }
00906      
00907     if (n[0]) {
00908       psize=4;
00909       col=fills[0];  
00910       for(i=0;i<=n[0];i++) {
00911         px[0]=x[2][i]; px[1]=x[0][i]; px[2]=x[0][i+1]; px[3]=x[2][i+1];
00912         py[0]=y[2][i]; py[1]=y[0][i]; py[2]=y[0][i+1]; py[3]=y[2][i+1];
00913         C2F(dr)("xliness","str",px,py,(cols=-Abs(col),&cols),&npoly,&psize ,PI0,PD0,PD0,PD0,PD0,0L,0L);
00914         col--;
00915       }
00916       FREE(x[0]);
00917       FREE(y[0]);
00918     }
00919      
00920     if (n[1]) {
00921       psize=4;
00922       col=fills[1];
00923       for(i=0;i<=n[1];i++) {
00924         px[0]=x[2][n[0]+i]; px[1]=x[1][i]; px[2]=x[1][i+1]; px[3]=x[2][n[0]+i+1];
00925         py[0]=y[2][n[0]+i]; py[1]=y[1][i]; py[2]=y[1][i+1]; py[3]=y[2][n[0]+i+1];
00926         C2F(dr)("xliness","str",px,py,(cols=-Abs(col),&cols),&npoly,&psize ,PI0,PD0,PD0,PD0,PD0,0L,0L);
00927         col--;
00928       }
00929       FREE(x[1]);
00930       FREE(y[1]);  
00931     }
00932 
00933     if (n[2]) {
00934       FREE(x[2]);
00935       FREE(y[2]);
00936     }
00937 
00938   }
00939    
00940   else { /* The 4 vertices case  */
00941      
00942     px[0]=polyx[0]; px[1]=polyx[1]; px[2]=polyx[2];
00943     py[0]=polyy[0]; py[1]=polyy[1]; py[2]=polyy[2];
00944     fil[0]=fill[0]; fil[1]=fill[1]; fil[2]=fill[2];
00945     scilab_shade(px,py,fil,3,-1);
00946 
00947     px[0]=polyx[0]; px[1]=polyx[2]; px[2]=polyx[3];
00948     py[0]=polyy[0]; py[1]=polyy[2]; py[2]=polyy[3];
00949     fil[0]=fill[0]; fil[1]=fill[2]; fil[2]=fill[3];
00950     scilab_shade(px,py,fil,3,-1);
00951   }
00952    
00953   /* If flag>0 then the contour is drawn */
00954    
00955   if (flag > 0) { 
00956     fil[0]=0;
00957     polysize+=1;
00958     C2F (dr) ("xliness", "str", polyx, polyy, fil, &npoly,
00959               &polysize, PI0, PD0, PD0, PD0, PD0, 0L, 0L);
00960   }
00961   return 0;
00962 }     
00963 
00964 

Generated on Sun Mar 4 15:03:53 2007 for Scilab [trunk] by  doxygen 1.5.1