Plo3dn.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *    Graphic library
00003  *    Copyright (C) 2003-2004 Inria/Djalel Abdemouche
00004  --------------------------------------------------------------------------*/
00005 
00006 #include <string.h>
00007 #include <math.h>
00008 #include <stdio.h>
00009 #include "math_graphics.h"
00010 #include "PloEch.h"
00011 
00012 #include "SetProperty.h"
00013 #include "GetProperty.h"
00014 #include "InitObjects.h"
00015 #include "DrawObjects.h"
00016 #include "BuildObjects.h"
00017 #include "Xcall1.h"
00018 #include "axesScale.h"
00019 #include "drawMarks.h"
00020 #include "sciprint.h"
00021 #include "CurrentObjectsManagement.h"
00022 
00023 
00024 #include "MALLOC.h" /* MALLOC */
00025 
00026 extern double C2F (dsort) ();
00027 extern int facet_facing_rear (integer facteur, integer * x, integer * y,
00028                               integer * c, integer * size, integer * xr,
00029                               integer * yr, integer * cr, integer * rsize);
00030 extern int scilab_shade(integer *polyx, integer *polyy, integer *fill, integer polysize, integer flag);
00031 
00032 void C2F (plot3dn) (sciPointObj * pobj, double *x, double *y, double *z,
00033                     integer * p, integer * q, int *DPI)
00034 {
00035   static integer fg1, dc;
00036   /*   int jj, kk; */
00037   integer polysize, whiteid, verbose = 0, narg;
00038   integer *polyx, *polyy, *fill;
00039   static integer cache;
00040   static double zmin, zmax;
00041   integer i, j, flagcolor;
00042   sciPointObj *psubwin = sciGetCurrentSubWin(); /* a laisser!!!!!!!! */
00043   sciSubWindow *ppsubwin = pSUBWIN_FEATURE (psubwin);
00044   int xx[4]; /* used to load the object foreground and dashes color */
00045   integer v=0;
00046   double dv=0.;
00047   
00048   /* Test to enable reverse axis in 3D *//* F.Leray 14.10.04 */
00049   int u;
00050   double *xtmp = NULL;
00051   double *ytmp = NULL;
00052   double *ztmp = NULL;
00053 
00054   xtmp = MALLOC ((*p) * sizeof (double));
00055   ytmp = MALLOC ((*q) * sizeof (double));
00056   ztmp = MALLOC ((*p) * (*q) * sizeof (double));
00057 
00058   for (u = 0; u < (*p); u++)
00059     xtmp[u] = x[u];
00060   for (u = 0; u < (*q); u++)
00061     ytmp[u] = y[u];
00062   for (u = 0; u < (*p) * (*q); u++)
00063     ztmp[u] = z[u];
00064 
00065     
00066   /* To fix bug 1757, I make a test on x data and sort the x entries */
00067   /* in a good manner for the algorithm... */
00068   if(*p >1){
00069     
00070     if(pSURFACE_FEATURE (pobj)->flag_x == -1) /* x input is decreasing */
00071       {
00072         int k;
00073         double xt,zt;
00074 
00075         for (u = 0; u < (*p)/2; u++){
00076           xt = xtmp[u];
00077           xtmp[u] = xtmp[(*p)-1-u];
00078           xtmp[(*p)-1-u] = xt;
00079         }
00080         
00081         /* corresponding z must change too */
00082         for (u = 0; u < (*p)/2; u++)
00083           {
00084             for(k = 0; k < (*q); k++){
00085               zt = ztmp[(*p)*k+u];
00086               
00087               ztmp[(*p)*k+u] = ztmp[(*p)*k+(*p-1)-u];
00088               ztmp[(*p)*k+(*p-1)-u] = zt;
00089               
00090             }
00091           }
00092       }
00093   }
00094   
00095   /* Same thing on y */
00096   if(*q >1){
00097      
00098     if(pSURFACE_FEATURE (pobj)->flag_y == -1) /* y input is decreasing */
00099       {
00100         int k;
00101         double yt,zt;
00102         
00103         for (u = 0; u < (*q)/2; u++){
00104           yt = ytmp[u];
00105           ytmp[u] = ytmp[(*q)-1-u];
00106           ytmp[(*q)-1-u] = yt;
00107         }
00108 
00109         /* corresponding z must change too */
00110         for (u = 0; u < (*q)/2; u++)
00111           {
00112             for(k = 0; k < (*p); k++){
00113               zt = ztmp[(*p)*u+k];
00114               
00115               ztmp[(*p)*u+k] = ztmp[(*p)*(*q-1-u)+k];
00116               ztmp[(*p)*(*q-1-u)+k] = zt;
00117             }
00118           }
00119       }
00120   }
00121   
00122   ReverseDataFor3DXonly (psubwin, xtmp, (*p));
00123   ReverseDataFor3DYonly (psubwin, ytmp, (*q));
00124   ReverseDataFor3DZonly (psubwin, ztmp, (*p) * (*q));
00125 
00126   zmin = pSUBWIN_FEATURE (psubwin)->SRect[4];   /*zmin */
00127   zmax = pSUBWIN_FEATURE (psubwin)->SRect[5];   /*zmax */
00128   cache = pSUBWIN_FEATURE (psubwin)->hiddenstate;
00129 
00130   fg1 = pSURFACE_FEATURE (pobj)->hiddencolor;
00131   dc = pSURFACE_FEATURE (pobj)->flag[0]; /* color_mode */
00132   flagcolor = pSURFACE_FEATURE (pobj)->flagcolor;
00133 
00134   xx[0] = sciGetForeground (pobj);
00135 
00137   polyx = MALLOC( 5 * (*q) * sizeof(int) ) ;
00138   polyy = MALLOC( 5 * (*q) * sizeof(int) );
00139   fill = MALLOC( (*q) * sizeof(int) ) ;
00140   if ((polyx == NULL) || (polyy == NULL) || (fill == NULL))
00141     {
00142       sciprint ("plot3dg_ : malloc No more Place\n");
00143       return;
00144     }
00145 
00146 
00147   C2F (dr) ("xget", "lastpattern", &verbose, &whiteid, &narg, PI0, PI0, PI0,
00148             PD0, PD0, PD0, PD0, 0L, 0L);
00149   /*  if (fg1<=0) fg1=dc; */
00150   for (i = 0; i < (*q) - 1; i++)
00151     fill[i] = dc;
00152   polysize = 5;
00153   
00156   switch (cache)
00157     {
00158     case 0:
00159       /*       printf(" case 0\n");fflush(NULL); */
00160       if (ppsubwin->axes.reverse[0] == TRUE)    /* x is reversed */
00161         {
00162           /*  printf(" x is reversed\n");fflush(NULL); */
00163           for (i = (*p) - 2; i >= 0; i--)
00164             {
00165               int npolyok = 0;
00166 
00167               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00168                 {
00169                   /*      printf(" y is reversed\n");fflush(NULL); */
00170                   for (j = (*q) - 2; j >= 0; j--)
00171                     {
00172                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00173                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00174                       npolyok +=
00175                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00176                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00177                                        npolyok, p, dc, fg1, pobj);
00178                     }
00179                   if (npolyok != 0)
00180                     {
00181                       if (sciGetIsLine (pobj)){
00182                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00183                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00184                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00185                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00186                                   PD0, 0L, 0L);
00187                       }
00188 
00189                       if (sciGetIsMark (pobj))
00190                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00191                     }
00192                 }
00193               else              /* y is NOT reversed */
00194                 {
00195                   /*   printf(" y is NOT reversed\n");fflush(NULL); */
00196                   for (j = 0; j < (*q) - 1; j++)
00197                     {
00198                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00199                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00200                       npolyok +=
00201                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00202                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00203                                        npolyok, p, dc, fg1, pobj);
00204                     }
00205                   if (npolyok != 0)
00206                     {
00207                       if (sciGetIsLine (pobj)){
00208                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00209                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00210                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00211                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00212                                   PD0, 0L, 0L);
00213                       }
00214 
00215                       if (sciGetIsMark (pobj))
00216                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00217 
00218                     }
00219                 }
00220 
00221             }
00222         }
00223       else                      /* x is NOT reversed */
00224         {
00225           /*  printf(" x is NOT reversed\n");fflush(NULL); */
00226           for (i = 0; i < (*p) - 1; i++)
00227             {
00228               int npolyok = 0;
00229 
00230               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00231                 {
00232                   /*  printf(" y is reversed\n");fflush(NULL); */
00233                   for (j = (*q) - 2; j >= 0; j--)
00234                     {
00235                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00236                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00237                       npolyok +=
00238                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00239                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00240                                        npolyok, p, dc, fg1, pobj);
00241                     }
00242                   if (npolyok != 0)
00243                     {
00244                       if (sciGetIsLine (pobj)){
00245                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00246                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00247                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00248                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00249                                   PD0, 0L, 0L);
00250                       }
00251 
00252                       if (sciGetIsMark (pobj))
00253                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00254                     }
00255                 }
00256               else              /* y is NOT reversed */
00257                 {
00258                   /*   printf(" y is NOT reversed\n");fflush(NULL); */
00259                   for (j = 0; j < (*q) - 1; j++)
00260                     {
00261                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00262                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00263                       npolyok +=
00264                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00265                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00266                                        npolyok, p, dc, fg1, pobj);
00267                     }
00268                   if (npolyok != 0)
00269                     {
00270                       if (sciGetIsLine (pobj)){
00271                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00272                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00273                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00274                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00275                                   PD0, 0L, 0L);
00276                       }
00277                       
00278                       if (sciGetIsMark (pobj))
00279                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00280                     }
00281                 }
00282             }
00283         }
00284       /*    printf("\n\n");fflush(NULL); */
00285       break;
00286     case 1:
00287       /*   printf(" case 1\n"); */
00288       /*       fflush(NULL); */
00289       if (ppsubwin->axes.reverse[0] == TRUE)
00290         {
00291           for (i = (*p) - 2; i >= 0; i--)
00292             {
00293               int npolyok = 0;
00294 
00295               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00296                 {
00297                   for (j = (*q) - 2; j >= 0; j--)
00298                     {
00299                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00300                       /*                                 x,y,ztmp,i,(*q)-2-j,npolyok,p,dc,fg1); */
00301                       npolyok +=
00302                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00303                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00304                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00305                     }
00306                   if (npolyok != 0)
00307                     {
00308                       if (sciGetIsLine (pobj)){
00309                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00310                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00311                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00312                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00313                                   PD0, 0L, 0L);
00314                       }
00315 
00316                       if (sciGetIsMark (pobj))
00317                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00318                     }
00319                 }
00320               else              /* y is NOT reversed */
00321                 {
00322                   for (j = 0; j < (*q) - 1; j++)
00323                     {
00324                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00325                       /*                                 x,y,ztmp,i,(*q)-2-j,npolyok,p,dc,fg1); */
00326                       npolyok +=
00327                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00328                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00329                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00330                     }
00331                   if (npolyok != 0)
00332                     {
00333                       if (sciGetIsLine (pobj)){
00334                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00335                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00336                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00337                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00338                                   PD0, 0L, 0L);
00339                       }
00340 
00341                       if (sciGetIsMark (pobj))
00342                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00343                     }
00344                 }
00345             }
00346         }
00347       else
00348         {
00349           for (i = 0; i < (*p) - 1; i++)
00350             {
00351               int npolyok = 0;
00352 
00353               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00354                 {
00355                   for (j = (*q) - 2; j >= 0; j--)
00356                     {
00357                       npolyok +=
00358                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00359                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00360                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00361                     }
00362                   if (npolyok != 0)
00363                     {
00364                       if (sciGetIsLine (pobj)){
00365                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00366                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00367                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00368                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00369                                   PD0, 0L, 0L);
00370                       }
00371 
00372                       if (sciGetIsMark (pobj))
00373                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00374                     }
00375                 }
00376               else
00377                 {
00378                   for (j = 0; j < (*q) - 1; j++)
00379                     {
00380                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00381                       /*                                 x,y,ztmp,i,(*q)-2-j,npolyok,p,dc,fg1); */
00382                       npolyok +=
00383                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00384                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00385                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00386                     }
00387                   if (npolyok != 0)
00388                     {
00389                       if (sciGetIsLine (pobj)){
00390                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00391                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00392                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00393                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00394                                   PD0, 0L, 0L);
00395                       }
00396 
00397                       if (sciGetIsMark (pobj))
00398                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00399                     }
00400                 }
00401             }
00402         }
00403       break;
00404     case 2:
00405       if (ppsubwin->axes.reverse[0] == TRUE)    /* x is reversed */
00406         {
00407           for (i = 0; i < (*p) - 1; i++)
00408             {
00409               int npolyok = 0;
00410 
00411               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00412                 {
00413                   for (j = (*q) - 2; j >= 0; j--)
00414                     {
00415                       /*  npolyok +=     (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00416                       /*                                    x,y,ztmp,i,(*q)-2-j,npolyok,p,dc,fg1); */
00417                       npolyok +=
00418                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00419                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00420                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00421                     }
00422                   if (npolyok != 0)
00423                     {
00424                       if (sciGetIsLine (pobj)){
00425                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00426                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00427                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00428                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00429                                   PD0, 0L, 0L);
00430                       }
00431 
00432                       if (sciGetIsMark (pobj))
00433                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00434                     }
00435                 }
00436               else              /* y is NOT reversed */
00437                 {
00438                   for (j = 0; j < (*q) - 1; j++)
00439                     {
00440                       /*  npolyok +=     (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00441                       /*                                    x,y,ztmp,i,(*q)-2-j,npolyok,p,dc,fg1); */
00442                       npolyok +=
00443                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00444                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00445                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00446                     }
00447                   if (npolyok != 0)
00448                     {
00449                       if (sciGetIsLine (pobj)){
00450                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00451                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00452                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00453                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00454                                   PD0, 0L, 0L);
00455                       }
00456 
00457                       if (sciGetIsMark (pobj))
00458                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00459                     }
00460                 }
00461             }
00462         }
00463       else                      /* x is NOT reversed */
00464         {
00465           for (i = (*p) - 2; i >= 0; i--)
00466             {
00467               int npolyok = 0;
00468 
00469               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00470                 {
00471                   for (j = (*q) - 2; j >= 0; j--)
00472                     {
00473                       /*  npolyok +=     (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00474                       /*                                    x,y,ztmp,i,(*q)-2-j,npolyok,p,dc,fg1); */
00475                       npolyok +=
00476                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00477                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00478                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00479                     }
00480                   if (npolyok != 0)
00481                     {
00482                       if (sciGetIsLine (pobj)){
00483                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00484                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00485                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00486                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00487                                   PD0, 0L, 0L);
00488                       }
00489 
00490                       if (sciGetIsMark (pobj))
00491                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00492                     }
00493                 }
00494               else
00495                 {
00496                   for (j = 0; j < (*q) - 1; j++)
00497                     {
00498                       /*  npolyok +=     (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00499                       /*                                    x,y,ztmp,i,(*q)-2-j,npolyok,p,dc,fg1); */
00500                       npolyok +=
00501                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00502                                        zmin, zmax, xtmp, ytmp, ztmp, i,
00503                                        (*q) - 2 - j, npolyok, p, dc, fg1, pobj);
00504                     }
00505                   if (npolyok != 0)
00506                     {
00507                       if (sciGetIsLine (pobj)){
00508                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00509                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00510                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00511                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00512                                   PD0, 0L, 0L);
00513                       }
00514 
00515                       if (sciGetIsMark (pobj))
00516                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00517                     }
00518                 }
00519             }
00520         }
00521       break;
00522     case 3:
00523       if (ppsubwin->axes.reverse[0] == TRUE)    /* x is reversed */
00524         {
00525           for (i = 0; i < (*p) - 1; i++)
00526             {
00527               int npolyok = 0;
00528 
00529               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00530                 {
00531                   for (j = (*q) - 2; j >= 0; j--)
00532                     {
00533                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00534                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00535                       npolyok +=
00536                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00537                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00538                                        npolyok, p, dc, fg1, pobj);
00539                     }
00540                   if (npolyok != 0)
00541                     {
00542                       if (sciGetIsLine (pobj)){
00543                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00544                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00545                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00546                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00547                                   PD0, 0L, 0L);
00548                       }
00549 
00550                       if (sciGetIsMark (pobj))
00551                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00552                     }
00553                 }
00554               else              /* y is NOT reversed */
00555                 {
00556                   for (j = 0; j < (*q) - 1; j++)
00557                     {
00558                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00559                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00560                       npolyok +=
00561                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00562                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00563                                        npolyok, p, dc, fg1, pobj);
00564                     }
00565                   if (npolyok != 0)
00566                     {
00567                       if (sciGetIsLine (pobj)){
00568                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00569                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00570                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00571                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00572                                   PD0, 0L, 0L);
00573                       }
00574 
00575                       if (sciGetIsMark (pobj))
00576                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00577                     }
00578                 }
00579             }
00580         }
00581       else                      /* x is NOT reversed */
00582         {
00583           for (i = (*p) - 2; i >= 0; i--)
00584             {
00585               int npolyok = 0;
00586 
00587               if (ppsubwin->axes.reverse[1] == TRUE)    /* y is reversed */
00588                 {
00589                   for (j = (*q) - 2; j >= 0; j--)
00590                     {
00591                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00592                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00593                       npolyok +=
00594                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00595                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00596                                        npolyok, p, dc, fg1, pobj);
00597                     }
00598                   if (npolyok != 0)
00599                     {
00600                       if (sciGetIsLine (pobj)){
00601                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00602                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00603                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00604                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00605                                   PD0, 0L, 0L);
00606                       }
00607 
00608                       if (sciGetIsMark (pobj))
00609                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00610                     }
00611                 }
00612               else
00613                 {
00614                   for (j = 0; j < (*q) - 1; j++)
00615                     {
00616                       /*  npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax, */
00617                       /*                                       x,y,ztmp,i,j,npolyok,p,dc,fg1); */
00618                       npolyok +=
00619                         (Gen3DPoints) (flagcolor, polyx, polyy, fill, whiteid,
00620                                        zmin, zmax, xtmp, ytmp, ztmp, i, j,
00621                                        npolyok, p, dc, fg1, pobj);
00622                     }
00623                   if (npolyok != 0)
00624                     {
00625                       if (sciGetIsLine (pobj)){
00626                         C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00627                         C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00628                         C2F (dr) ("xliness", "str", polyx, polyy, fill,
00629                                   &npolyok, &polysize, PI0, PD0, PD0, PD0,
00630                                   PD0, 0L, 0L);
00631                       }
00632 
00633                       if (sciGetIsMark (pobj))
00634                         DrawMarks3D (pobj, 5 * npolyok, polyx, polyy,DPI);
00635                     }
00636                 }
00637             }
00638         }
00639       break;
00640     }
00641       
00642   FREE (ztmp);
00643   ztmp = NULL;
00644   FREE (xtmp);
00645   xtmp = NULL;
00646   FREE (ytmp);
00647   ytmp = NULL;
00648   FREE( polyx ) ;
00649   FREE( polyy ) ;
00650   FREE( fill ) ;
00651 }
00652 
00653 void C2F (fac3dn) (sciPointObj * pobj, double *x, double *y, double *z,
00654                    double * cvect, integer * p, integer * q, int *DPI)
00655 {
00656   integer polysize, npoly, whiteid, verbose = 0, narg, hiddencolor, front_size;
00657   integer *polyx, *polyy, *locindex, fill[4];
00658   integer * col = NULL ; /* color vector */
00659   integer * rear_x   = NULL ;
00660   integer * rear_y   = NULL ;
00661   integer * rear_col = NULL ;
00662   integer  rear_size;
00663   static double zmin, zmax, *polyz;
00664   integer i, k, color_mode, color_flag;
00665   sciPointObj *psubwin = NULL;
00666   sciSubWindow *ppsubwin = NULL;
00667   int facteur = 1;
00668   integer rear;
00669   int xx[4]; /* used to load the object foreground and dashes color */
00670   integer v=0;
00671   double dv=0.;
00672  
00673   int u;
00674   double *xtmp = NULL;
00675   double *ytmp = NULL;
00676   double *ztmp = NULL;
00677 
00678   psubwin = sciGetCurrentSubWin();
00679   ppsubwin = pSUBWIN_FEATURE (psubwin);
00680 
00681   zmin = pSUBWIN_FEATURE (psubwin)->SRect[4];   /*zmin */
00682   zmax = pSUBWIN_FEATURE (psubwin)->SRect[5];   /*zmax */
00683 
00684   hiddencolor = pSURFACE_FEATURE (pobj)->hiddencolor;
00685   color_mode = pSURFACE_FEATURE (pobj)->flag[0];
00686   color_flag = pSURFACE_FEATURE (pobj)->flagcolor;
00687 
00688   xx[0] = sciGetForeground (pobj);
00689 
00692   polyx    = MALLOC( ( *p + 1 ) * sizeof(int) ) ;
00693   polyy    = MALLOC( ( *p + 1 ) * sizeof(int) ) ;
00694   locindex = MALLOC(   *q       * sizeof(int) ) ;
00695   
00696   polyz = MALLOC(        (*q) * sizeof(double) ) ;
00697   xtmp  = MALLOC( (*p) * (*q) * sizeof(double) ) ;
00698   ytmp  = MALLOC( (*p) * (*q) * sizeof(double) ) ;
00699   ztmp  = MALLOC( (*p) * (*q) * sizeof(double) ) ;
00700 
00701   col      = MALLOC(  *p        * sizeof (integer) ) ;
00702   rear_x   = MALLOC( ( *p + 1 ) * sizeof (integer) ) ;
00703   rear_y   = MALLOC( ( *p + 1 ) * sizeof (integer) ) ;
00704   rear_col = MALLOC( ( *p + 1 ) * sizeof (integer) ) ;
00705 
00706   if (   polyx  == NULL || polyy    == NULL || locindex == NULL 
00707       || polyz  == NULL || col      == NULL || rear_x   == NULL
00708       || rear_y == NULL || rear_col == NULL || xtmp     == NULL
00709       || ytmp   == NULL || ztmp     == NULL )
00710   {
00711     sciprint ("plot3dg_ : malloc No more Place\n");
00712     return;
00713   }
00714 
00715   /* initialization */
00716   for (u = 0; u < (*p) * (*q); u++)
00717   {
00718     xtmp[u] = x[u];
00719     ytmp[u] = y[u];
00720     ztmp[u] = z[u];
00721   }
00722 
00723 
00724   ReverseDataFor3D (psubwin, xtmp, ytmp, ztmp, (*p) * (*q));
00725 
00728   for (i = 0; i < *q; i++)
00729     {
00730       double zdmin1, zdmin, xmoy = 0.00, ymoy = 0.00, zmoy = 0.00;
00731       int j = 0;
00732       zdmin1 = TRZ (xtmp[(*p) * i], ytmp[(*p) * i], ztmp[(*p) * i]);
00733       for (j = 0; j < *p; j++)
00734         {
00735           xmoy += xtmp[j + (*p) * i];
00736           ymoy += ytmp[j + (*p) * i];
00737           zmoy += ztmp[j + (*p) * i];
00738           zdmin =
00739             TRZ (xtmp[j + (*p) * i], ytmp[j + (*p) * i], ztmp[j + (*p) * i]);
00740           if (zdmin1 < zdmin)
00741             zdmin1 = zdmin;
00742         }
00743       polyz[i] = TRZ (xmoy, ymoy, zmoy);
00744     }
00745   C2F (dsort) (polyz, q, locindex);
00746   for (i = 0; i < (*q); i++)
00747     {
00748       locindex[i] -= 1;
00749       if (locindex[i] >= *q)
00750         sciprint (" index[%d]=%d\r\n", i, locindex[i]);
00751       locindex[i] = Min (Max (0, locindex[i]), *q - 1);
00752     }
00753   polysize = (*p) + 1;
00754   npoly = 1;
00755 
00756   C2F (dr) ("xget", "lastpattern", &verbose, &whiteid, &narg, PI0, PI0, PI0,
00757             PD0, PD0, PD0, PD0, 0L, 0L);
00758 
00759   /* facteur is used below */
00760   if (ppsubwin->axes.reverse[0] == TRUE)
00761     facteur = -facteur;
00762   if (ppsubwin->axes.reverse[1] == TRUE)
00763     facteur = -facteur;
00764   if (ppsubwin->axes.reverse[2] == TRUE)
00765     facteur = -facteur;
00766 
00767 
00768   for (i = (*q) - 1; i >= 0; i--)
00769     {
00770       int j, nok = 0;
00771       for (j = 0; j < (*p); j++)
00772         {
00773           if (trans3d
00774               (psubwin, 1, &(polyx[j]), &(polyy[j]),
00775                &(xtmp[(*p) * locindex[i] + j]),
00776                &(ytmp[(*p) * locindex[i] + j]),
00777                &(ztmp[(*p) * locindex[i] + j])) == 0)
00778             {
00779               nok = 1;
00780               break;
00781             }
00782         }
00783 
00784       if (nok == 0)
00785         {
00786           polyx[(*p)] = polyx[0];
00787           polyy[(*p)] = polyy[0];
00788 
00789           /* Preparation of the color vector. In the case color_flag==1,
00790              the color is proportional to the Z-level. */
00791 
00792           front_size = *p;      /* initial size of the front facing facet */
00793 
00794 
00795           if (color_flag == 3)
00796             {
00797               /* interpolated shading */
00798 
00799               for (k = 0; k < *p; k++)
00800                 col[k] = (int) cvect[(*p) * locindex[i] + k];
00801 
00802             }
00803           else if (color_flag == 2)
00804             {
00805               /* flat shading */
00806 
00807               for (k = 0; k < *p; k++)
00808                 col[k] = (int) cvect[locindex[i]];
00809 
00810             }
00811           else if (color_flag == 4)
00812             {
00813               /* flat shading "a la Matlab" */
00814 
00815               for (k = 0; k < *p; k++)
00816                 col[k] = (int) cvect[locindex[i]];
00817               
00818             }
00819           else if (color_flag == 1)
00820             {
00821               /* Z-level flat shading. Computing of color has been moved here for clarity. */
00822 
00823               double zl = 0;
00824               for (k = 0; k < *p; k++)
00825                 zl += z[(*p) * locindex[i] + k];        /* F.Leray 29.11.04 : DO NOT REPLACE z by ztmp here : zmin & zmax are computed to work with z ! */
00826               fill[0] =
00827                 inint ((whiteid - 1) * ((zl / (*p)) - zmin) / (zmax - zmin)) +
00828                 1;
00829               for (k = 0; k < *p; k++)
00830                 col[k] = -fill[0];
00831             }
00832           else
00833             {
00834               /* No shading at all, fixed facecolor */
00835 
00836               for (k = 0; k < *p; k++)
00837                 col[k] = 0;
00838             }
00839 
00840           /* The following call processes the case where the rear of the facet
00841              is facing the view point and hiddencolor is positive (the rear
00842              of the surface is painted with a uniform color). When hiddencolor=-1
00843              then the rear facets are processed for each specific value
00844              of color_flag (see below). */
00845           /* WARNING : the algorithm only work for facets with 4 or less vertices.
00846              it should be extended to more. */
00847 
00848           rear =
00849             facet_facing_rear (facteur, polyx, polyy, col, &front_size,
00850                                rear_x, rear_y, rear_col, &rear_size);
00851 
00852           rear_x[rear_size] = rear_x[0];
00853           rear_y[rear_size] = rear_y[0];
00854           rear_col[rear_size] = rear_col[0];
00855 
00856           if (hiddencolor > 0 && rear)
00857             {
00858               if (color_flag != 0)
00859                 fill[0] = (color_mode < 0) ? -hiddencolor : hiddencolor;
00860               else
00861                 {
00862                   if (color_mode == 0)
00863                     fill[0] = 0;
00864                   else if (color_mode > 0)
00865                     fill[0] = hiddencolor;
00866                   else
00867                     fill[0] = -hiddencolor;
00868                 }
00869 
00870               if (sciGetIsLine (pobj)){
00871                 C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00872                 C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00873                 C2F (dr) ("xliness", "str", rear_x, rear_y, fill, &npoly,
00874                           &rear_size, PI0, PD0, PD0, PD0, PD0, 0L, 0L);
00875               }
00876               
00877               if (sciGetIsMark (pobj))
00878                 DrawMarks3D (pobj, rear_size, rear_x, rear_y,DPI);
00879 
00880               /* If the polygon is a triangle or a "butterfly" there is nothing left to draw */
00881 
00882               if (rear_size == *p)
00883                 continue;
00884             }
00885 
00886           if (color_flag == 1)
00887             {
00888               /* Flat shading. This is the case where the color index is constant for a facet */
00889 
00890               if (hiddencolor < 0 && rear)
00891                 {               /* draw the rear facing part of the facet */
00892                   integer rear_fill = col[0];
00893                   if (color_mode >= 0)  /* The edge of the facet is forcibly drawn if color_mode >= 0 */
00894                     rear_fill = Abs (col[0]);
00895                   if (sciGetIsLine (pobj)){
00896                     C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00897                     C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00898                     C2F (dr) ("xliness", "str", rear_x, rear_y, &rear_fill,
00899                               &npoly, &rear_size, PI0, PD0, PD0, PD0, PD0, 0L,0L);
00900                   }
00901                   
00902                   if (sciGetIsMark (pobj))
00903                     DrawMarks3D (pobj, rear_size, rear_x, rear_y,DPI);
00904 
00905                   if (rear_size == *p)
00906                     continue;
00907                 }
00908               /* Draw the remaining (front) part of the facet if applicable */
00909 
00910               if (color_mode > 0)       /* Force the drawing of the mesh */
00911                 col[0] = Abs (col[0]);
00912               else if (color_mode < 0)
00913                 col[0] = - Abs (col[0]);
00914               else
00915                 col[0] = 0;
00916               if (sciGetIsLine (pobj)){
00917                 C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00918                 C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00919                 C2F (dr) ("xliness", "str", polyx, polyy, col, &npoly,
00920                           &front_size, PI0, PD0, PD0, PD0, PD0, 0L, 0L);
00921               }
00922               
00923               if (sciGetIsMark (pobj))
00924                 DrawMarks3D (pobj, front_size, polyx, polyy,DPI);
00925 
00926             }
00927 
00928 
00929           /* NEW */
00930           
00931           else if ((color_flag == 2) || (color_flag == 4))
00932             {
00933               /* Flat shading. This is the case where the color index is constant for a facet */
00934 
00935               if (hiddencolor < 0 && rear)
00936                 {               /* draw the rear facing part of the facet */
00937                   integer rear_fill = col[0];
00938                   if (color_mode >= 0)  /* The edge of the facet is forcibly drawn if color_mode >= 0 */
00939                     rear_fill = Abs (col[0]);
00940                   if (sciGetIsLine (pobj)){
00941                     C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00942                     C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00943                     C2F (dr) ("xliness", "str", rear_x, rear_y, &rear_fill,
00944                               &npoly, &rear_size, PI0, PD0, PD0, PD0, PD0, 0L,0L);
00945                   }
00946                   
00947                   if (sciGetIsMark (pobj))
00948                     DrawMarks3D (pobj, rear_size, rear_x, rear_y,DPI);
00949 
00950                   if (rear_size == *p)
00951                     continue;
00952                 }
00953               /* Draw the remaining (front) part of the facet if applicable */
00954               
00955               if (color_mode > 0)       /* Force the drawing of the mesh */
00956                 col[0] = Abs (col[0]);
00957               else if (color_mode < 0)
00958                 col[0] = - Abs (col[0]);
00959               else
00960                 col[0] = 0;
00961               
00962               if (sciGetIsLine (pobj)){
00963                 C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
00964                 C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
00965                 C2F (dr) ("xliness", "str", polyx, polyy, col, &npoly,
00966                           &front_size, PI0, PD0, PD0, PD0, PD0, 0L, 0L);
00967               }
00968               
00969               if (sciGetIsMark (pobj))
00970                 DrawMarks3D (pobj, front_size, polyx, polyy,DPI);
00971 
00972             }
00973 
00974 
00975 
00976           /* END NEW */
00977 
00978 
00979 
00980 
00981 
00982 
00983 
00984 
00985           else if (color_flag == 3)
00986             {
00987               /* Interpolated shading */
00988 
00989               if ((*p) != 3 && (*p) != 4)
00990                 {
00991                   sciprint
00992                     ("plot3d1 : interpolated shading is only allowed for polygons with 3 or 4 vertices\n");
00993                   return;
00994                 }
00995               else
00996                 {
00997 
00998                   if (hiddencolor < 0 && rear)
00999                     {           /* draw the rear facing part of the facet */
01000 
01001                       if (sciGetIsLine (pobj))
01002                         {
01003 
01004                           /* The edge of the facet is forcibly drawn if color_mode >= 0 */
01005 
01006                           if (color_mode >= 0){ 
01007                             C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
01008                             C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
01009                             scilab_shade (rear_x, rear_y, rear_col, rear_size, 1);
01010                           }
01011                           else{
01012                             C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
01013                             C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
01014                             scilab_shade (rear_x, rear_y, rear_col, rear_size, -1);
01015                           }
01016                         }
01017                       if (sciGetIsMark (pobj))
01018                         DrawMarks3D (pobj, rear_size, rear_x, rear_y,DPI);
01019                       if (rear_size == *p)
01020                         continue;
01021                     }
01022                   /* Draw the remaining (front) part of the facet if applicable */
01023 
01024                   if (sciGetIsLine (pobj)){
01025                     C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
01026                     C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
01027                     scilab_shade (polyx, polyy, col, front_size, color_mode);
01028                   }
01029                   if (sciGetIsMark (pobj))
01030                     DrawMarks3D (pobj, front_size, polyx, polyy,DPI);
01031                 }
01032             }
01033           else
01034             {
01035               /* color_flag == 0, the facet is drawn with default facecolor and edgecolor (foreground) */
01036 
01037               fill[0] = color_mode;
01038 
01039               if (hiddencolor < 0 && rear)
01040                 {               /* draw the rear facing part of the facet */
01041                   if (sciGetIsLine (pobj)){
01042                     C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
01043                     C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
01044                     C2F (dr) ("xliness", "str", rear_x, rear_y, fill, &npoly,
01045                               &rear_size, PI0, PD0, PD0, PD0, PD0, 0L, 0L);
01046                   }
01047                   
01048                   if (sciGetIsMark (pobj))
01049                     DrawMarks3D (pobj, rear_size, rear_x, rear_y,DPI);
01050                   if (rear_size == *p)
01051                     continue;
01052                 }
01053               if (sciGetIsLine (pobj)){
01054                 C2F (dr) ("xset", "dashes",     xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 6L);
01055                 C2F (dr) ("xset", "foreground", xx,   xx,   xx+4, xx+4, xx+4, &v, &dv, &dv, &dv, &dv, 5L, 10L);
01056                 C2F (dr) ("xliness", "str", polyx, polyy, fill, &npoly,
01057                           &front_size, PI0, PD0, PD0, PD0, PD0, 0L, 0L);
01058               }
01059               
01060               if (sciGetIsMark (pobj))
01061                 DrawMarks3D (pobj, front_size, polyx, polyy,DPI);
01062 
01063             }
01064         }
01065     }
01066 
01067   /* freeing memory */
01068   FREE (xtmp);
01069   xtmp = NULL;
01070   FREE (ytmp);
01071   ytmp = NULL;
01072   FREE (ztmp);
01073   ztmp = NULL;
01074   
01075   FREE( col ) ;
01076   col = NULL ;
01077   FREE( rear_x ) ;
01078   rear_x = NULL ;
01079   FREE( rear_y ) ;
01080   rear_y = NULL ;
01081   FREE( rear_col ) ;
01082   rear_col = NULL ;
01083 
01084   FREE( polyx    ) ;
01085   polyx = NULL ;
01086   FREE( polyy    ) ;
01087   polyy = NULL ;
01088   FREE( polyz    ) ;
01089   polyz = NULL ;
01090   FREE( locindex ) ;
01091   locindex = NULL ;
01092 }
01093 
01094 
01095 int
01096 facet_facing_rear (integer facteur, integer * x, integer * y, integer * c,
01097                    integer * size, integer * xr, integer * yr, integer * cr,
01098                    integer * rsize)
01099 {
01100   double determ, determ0, determ1, determ2, determ3,
01101     t_param, x1mx0, x2mx1, x3mx2, x0mx3, y1my0, y2my1, y3my2, y0my3;
01102   integer i, p, swp, flag_det, flag_det0, flag_det1, flag_det2, flag_det3;
01103 
01104   p = (*size);
01105 
01106   for (i = 0; i < p; i++)
01107     {
01108       xr[i] = x[i]; yr[i] = y[i]; cr[i] = c[i];
01109     }
01110 
01111   (*rsize) = p;
01112 
01113   x1mx0 = x[1] - x[0]; y1my0 = y[1] - y[0];
01114   x2mx1 = x[2] - x[1]; y2my1 = y[2] - y[1];
01115 
01116   determ1 = (y2my1 * x1mx0 - x2mx1 * y1my0) * facteur;
01117   flag_det1 = (determ1 < 0);
01118 
01119   /* should add a general case here for more edgy facets */
01120   if (p == 4)
01121     {                           /* further tests for the quadrilateral case */
01122       x3mx2 = x[3] - x[2];
01123       y3my2 = y[3] - y[2];
01124       x0mx3 = x[0] - x[3];
01125       y0my3 = y[0] - y[3];
01126       determ0 = (x0mx3 * y1my0 - y0my3 * x1mx0) * facteur;
01127       determ2 = (x2mx1 * y3my2 - y2my1 * x3mx2) * facteur;
01128       determ3 = (x3mx2 * y0my3 - y3my2 * x0mx3) * facteur;
01129       flag_det0 = (determ0 < 0);
01130       flag_det2 = (determ2 < 0);
01131       flag_det3 = (determ3 < 0);
01132     }
01133   else
01134   {
01135     return (flag_det1);
01136   }
01137 
01138   /* flag_det allows to precisely detect the orientation of the facet
01139      for the case of the quadrilateral. If flag_det==2, then the
01140      quadrilateral is projected as a butterfly, and both the rear and
01141      the top of the facet are facing the vewpoint. This needs a different
01142      processing which has to be implemented */
01143 
01144   flag_det = flag_det0 + flag_det1 + flag_det2 + flag_det3;
01145 
01146   if (flag_det == 0)
01147     return 0;
01148   else if (flag_det == 4)
01149     return 1;
01150   else if (flag_det == 2)
01151     {
01152       /* Butterfly case */
01153 
01154       (*rsize) = 3;
01155       (*size) = 3;
01156 
01157       if ((flag_det2 && flag_det3) || (flag_det0 && flag_det1))
01158         {
01159           /* the (1,2) and (0,3) segments are crossing */
01160 
01161           determ = (x2mx1 * y0my3 - y2my1 * x0mx3) * facteur;
01162           t_param = determ0 / determ;
01163 
01164           /* Computation of the intersection point (i) */
01165 
01166           xr[0] = linint (x[1] + t_param * x2mx1);
01167           yr[0] = linint (y[1] + t_param * y2my1);
01168           cr[0] = linint (c[1] + t_param * (c[2] - c[1]));
01169 
01170           if (flag_det2)
01171             {
01172               /* This is the case where the triangle (0,1,i) is front and (i,2,3) is rear */
01173 
01174               xr[1] = x[3];yr[1] = y[3];cr[1] = c[3];
01175               x[2] = xr[0];y[2] = yr[0];c[2] = cr[0];
01176             }
01177           else
01178             {
01179               /* This is the case where the triangle (0,1,i) is rear and (i,2,3) is front */
01180 
01181               xr[2] = x[0];yr[2] = y[0];cr[2] = c[0];
01182               x[0] = xr[0];y[0] = yr[0];c[0] = cr[0];
01183               x[1] = x[3];y[1] = y[3];c[1] = c[3];
01184             }
01185         }
01186       else
01187         {
01188           /* the (0,1) and (2,3) segments are crossing */
01189 
01190           determ = (x1mx0 * y3my2 - y1my0 * x3mx2) * facteur;
01191           t_param = determ3 / determ;
01192 
01193           /* Computation of the intersection point (i) */
01194 
01195           xr[1] = linint (x[0] + t_param * x1mx0);
01196           yr[1] = linint (y[0] + t_param * y1my0);
01197           cr[1] = linint (c[0] + t_param * (c[1] - c[0]));
01198           if (flag_det0)
01199             {
01200               /* This is the case where the triangle (0,i,3) is rear and (i,1,2) is front */
01201 
01202               xr[2] = x[3];yr[2] = y[3];cr[2] = c[3];
01203               x[0] = xr[1];y[0] = yr[1];c[0] = cr[1];
01204             }
01205           else
01206             {
01207               /* This is the case where the triangle (0,i,3) is front and (i,1,2) is back */
01208 
01209               xr[0] = x[1];yr[0] = y[1];cr[0] = c[1];
01210               x[1] = xr[1];y[1] = yr[1];c[1] = cr[1];
01211               x[2] = x[3];y[2] = y[3];c[2] = c[3];
01212             }
01213         }
01214       return 1;
01215     }
01216   else
01217     {
01218       if (flag_det0 == flag_det2)
01219         {
01220           /* If the quadrilateral is not convex, then the vertices must be
01221              correctly numbered, if interpolated shading is to be used, because
01222              a (0,1,2,3) quadrilateral is splitted in triangles (0,1,2) and (0,2,3). */
01223 
01224           swp = x[0];x[0] = x[1];x[1] = x[2];x[2] = x[3];x[3] = swp;
01225           swp = y[0];y[0] = y[1];y[1] = y[2];y[2] = y[3];y[3] = swp;
01226           swp = c[0];c[0] = c[1];c[1] = c[2];c[2] = c[3];c[3] = swp;
01227           swp = xr[0];xr[0] = xr[1];xr[1] = xr[2];xr[2] = xr[3];xr[3] = swp;
01228           swp = yr[0];yr[0] = yr[1];yr[1] = yr[2];yr[2] = yr[3];yr[3] = swp;
01229           swp = cr[0];cr[0] = cr[1];cr[1] = cr[2];cr[2] = cr[3];cr[3] = swp;
01230         }
01231       if (flag_det == 3)
01232         return 1;
01233       else
01234         return 0;
01235     }
01236 }

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