Fix bug 2540
Jean-Baptiste Silvy [Tue, 20 Jan 2009 17:16:00 +0000 (18:16 +0100)]
scilab/CHANGES_5.1
scilab/modules/graphics/includes/BasicAlgos.h
scilab/modules/graphics/includes/math_graphics.h
scilab/modules/graphics/src/c/BasicAlgos.c
scilab/modules/graphics/src/c/math_graphics.c
scilab/modules/graphics/src/c/sciCall.c
scilab/modules/graphics/tests/nonreg_tests/bug_2540.dia.ref [new file with mode: 0644]
scilab/modules/graphics/tests/nonreg_tests/bug_2540.tst [new file with mode: 0644]
scilab/modules/renderer/src/java/org/scilab/modules/renderer/drawers/MarkDrawerGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/surfaceDrawing/SurfaceMarkDrawerGL.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/utils/textRendering/SciTextRenderer.java

index 4ab6271..0d76123 100644 (file)
@@ -64,6 +64,8 @@ Bug fixes:
 
 * In the binary, the path to the fortran include directory was wrong.
 
+* bug 2540 fixed - plot3d hangs scilab when plotting a matrix full with NaN.
+
 * bug 3080 fixed - When we click many times on a button of the Graphic window the instruction will be done as much times we have clicked.
 
 * bug 3500 fixed - [pcre] match position but no character = no match
index a8cf117..e103283 100644 (file)
 #define _BASIC_ALGOS_H_
 
 #include <string.h>
+#include "BOOL.h"
 
 /**
  * Find the striclty positive minimum value of an array of double.
  * @param[in] x array of size n.
  * @return The stricly posistive minimum of x if exists, a negative value otherwise
  */
-double sciFindStPosMin( double x[], int n ) ;
+double sciFindStPosMin( const double x[], int n ) ;
 
 
 /**
@@ -38,7 +39,13 @@ double sciFindStPosMin( double x[], int n ) ;
  *          0 if not monotonous
  * @param nbElement must be greater than 2.
  */
-int checkMonotony( double vector[], int nbElement ) ;
+int checkMonotony( const double vector[], int nbElement ) ;
+
+/**
+ * @return TRUE if the array contains one element which is not %inf, -%inf or %nan
+ *         FALSE is all its elements are not finite
+ */
+BOOL containsOneFiniteElement(const double vector[], int nbElement);
 
 /*--------------------------------------------------------------------------*/
 /**
index 8b5efa1..eb1d0e1 100644 (file)
@@ -78,9 +78,9 @@
 #define M_PI 3.14159265358979323846 
 #endif
 
-double Mini(double *vect, int n) ;
+double Mini(const double vect[], int n) ;
 
-double Maxi(double *vect,int n) ;
+double Maxi(const double vect[], int n) ;
 
 
 
index ccc20ca..ab7e51d 100644 (file)
@@ -23,7 +23,7 @@
 #include "rendererBasicAlgos.h"
 
 /*------------------------------------------------------------------------*/
-double sciFindStPosMin( double x[], int n )
+double sciFindStPosMin( const double x[], int n )
 {
   double min ;
   int i ;
@@ -47,7 +47,7 @@ double sciFindStPosMin( double x[], int n )
   return min ;
 }
 /*------------------------------------------------------------------------*/
-int checkMonotony( double vector[], int nbElement )
+int checkMonotony( const double vector[], int nbElement )
 {
   int i ;
   if( vector[1] >= vector[0] )
@@ -81,6 +81,19 @@ int checkMonotony( double vector[], int nbElement )
 
 }
 /*------------------------------------------------------------------------*/
+BOOL containsOneFiniteElement(const double vector[], int nbElement)
+{
+       int i;
+       for (i = 0; i < nbElement; i++)
+       {
+               if (finite(vector[i]))
+               {
+                       return TRUE;
+               }
+       }
+       return FALSE;
+}
+/*------------------------------------------------------------------------*/
 void doubleArrayCopy( double dest[], const double src[], int nbElement )
 {
   memcpy( dest, src, nbElement * sizeof(double) ) ;
index 12dfc49..07fc7be 100644 (file)
@@ -26,7 +26,7 @@
 #define spINSIDE_SPARSE
 #include "../../sparse/includes/spConfig.h"
 
-double Mini(double *vect, int n)
+double Mini(const double vect[], int n)
 {
   int i;
   double vmin;
@@ -38,7 +38,7 @@ double Mini(double *vect, int n)
   return(vmin);
 }
 
-double Maxi(double *vect,int n)
+double Maxi(const double vect[], int n)
 {
   int i;
   double maxi;
index a4887bc..aa57a49 100644 (file)
 #include "DrawingBridge.h"
 #include "Plot2d.h"
 
+/**
+ * Put min and max of vector in dMin and dMax.
+ * If no min and max can't be found (no finite data in dMin or dMax),
+ * then use the default values
+ */
+static void getDrect(const double vector[], int nbElements,
+                                                                                double * dMin, double * dMax,
+                                                                                double defaultMin, double defaultMax);
 /*------------------------------------------------
  * Objrect :
  * On recupere la figure courante, puis on recupere la sous fenetre qui y est selectionnee
@@ -370,373 +378,375 @@ void Objplot3d ( char    * fname ,
      /* F.Leray 25.04.05 : warning here legends means "X@Y@Z": it is labels writings!! */
      /* legends has not the same meaning than inside plot2dn (there, it is really the legends of the plotted curves)*/
 {
-  sciTypeOf3D typeof3d;
-  int flagcolor;
-  long *hdltab;
-  int i, mn;
-  sciPointObj *psubwin = NULL, *pobj = NULL;
-  sciPointObj * parentFigure = NULL;
-  double drect[6];
-  char * loc = NULL;
-  char * legx = NULL;
-  char * legy = NULL;
-  char * legz = NULL;
-  /*   char * buff = NULL; */
-  int flag_x = 1;
-  int flag_y = 1;
-  int dimvectx = -1;
-  int dimvecty = -1;
-  char linLogFlags[3] = {'n','n','n'};
-
-  sciPointObj  * pNewSurface = NULL ;
-  sciSubWindow * ppsubwin = NULL;
-  BOOL bounds_changed = FALSE; /* cannot be used here because we have to force redrawing since there is no way to avoid merge (=> complete redraaw) */
-
-  /* Initialisation drect A.C pour debuggueur */
-  drect[0]=0;
-  drect[1]=0;
-  drect[2]=0;
-  drect[3]=0;
-  drect[4]=0;
-  drect[5]=0;
-
-  /* =================================================
-   * Force SubWindow properties according to arguments
-   * ================================================= */
-  startGraphicDataWriting();
-  parentFigure = sciGetCurrentFigure();
-  psubwin= sciGetCurrentSubWin();
-  endGraphicDataWriting();
-
-  startFigureDataWriting(parentFigure);
-  checkRedrawing() ;
-
-  /* Force psubwin->is3d to TRUE: we are in 3D mode */
-  pSUBWIN_FEATURE (psubwin)->is3d = TRUE;
-  pSUBWIN_FEATURE (psubwin)->project[2] = 1; /* to force z axis display */
-
-  ppsubwin = pSUBWIN_FEATURE(psubwin);
-
-  if ( legend != NULL )
-  {
-    /* F.Leray 25.04.05 replace the default labels by the user labels if specified */
-    loc=(char *) MALLOC( (strlen(legend)+1)*sizeof(char));
-    if ( loc == NULL) {
-               Scierror(999, _("%s: No more memory.\n"),"Objplot3d");
+       sciTypeOf3D typeof3d;
+       int flagcolor;
+       long *hdltab;
+       int i;
+       sciPointObj *psubwin = NULL, *pobj = NULL;
+       sciPointObj * parentFigure = NULL;
+       double drect[6];
+       char * loc = NULL;
+       char * legx = NULL;
+       char * legy = NULL;
+       char * legz = NULL;
+       /*   char * buff = NULL; */
+       int flag_x = 1;
+       int flag_y = 1;
+       int dimvectx = -1;
+       int dimvecty = -1;
+       char linLogFlags[3] = {'n','n','n'};
+
+       sciPointObj  * pNewSurface = NULL ;
+       sciSubWindow * ppsubwin = NULL;
+       BOOL bounds_changed = FALSE; /* cannot be used here because we have to force redrawing since there is no way to avoid merge (=> complete redraaw) */
+
+       /* Initialisation drect A.C pour debuggueur */
+       drect[0] = 0.0;
+       drect[1] = 0.0;
+       drect[2] = 0.0;
+       drect[3] = 0.0;
+       drect[4] = 0.0;
+       drect[5] = 0.0;
+
+       /* =================================================
+       * Force SubWindow properties according to arguments
+       * ================================================= */
+       startGraphicDataWriting();
+       parentFigure = sciGetCurrentFigure();
+       psubwin= sciGetCurrentSubWin();
+       endGraphicDataWriting();
+
+       startFigureDataWriting(parentFigure);
+       checkRedrawing() ;
+
+       /* Force psubwin->is3d to TRUE: we are in 3D mode */
+       pSUBWIN_FEATURE (psubwin)->is3d = TRUE;
+       pSUBWIN_FEATURE (psubwin)->project[2] = 1; /* to force z axis display */
+
+       ppsubwin = pSUBWIN_FEATURE(psubwin);
+
+       if ( legend != NULL )
+       {
+               /* F.Leray 25.04.05 replace the default labels by the user labels if specified */
+               loc=(char *) MALLOC( (strlen(legend)+1)*sizeof(char));
+               if ( loc == NULL) {
+                       Scierror(999, _("%s: No more memory.\n"),"Objplot3d");
+               }
+
+               strcpy(loc,legend);
+
+               /*   legx=strtok_r(loc,"@",&buff); */
+               legx=strtok(loc,"@");
+
+               if (legx != NULL)
+               {
+                       sciSetText( ppsubwin->mon_x_label, &legx , 1, 1 ) ;
+               }
+
+               /*   legy=strtok_r((char *)0,"@",&buff); */
+               legy=strtok((char *)NULL,"@"); /* NULL to begin at the last read character */
+               if ( legy != NULL )
+               {
+                       sciSetText( ppsubwin->mon_y_label, &legy , 1, 1 ) ;
+               }
+
+               /*   legz=strtok_r((char *)0,"@",&buff); */
+               legz=strtok((char *)NULL,"@");
+               if ( legz != NULL )
+               {
+                       sciSetText( ppsubwin->mon_z_label, &legz , 1, 1 ) ;
+               }
        }
 
-    strcpy(loc,legend);
-
-    /*   legx=strtok_r(loc,"@",&buff); */
-    legx=strtok(loc,"@");
-
-    if (legx != NULL)
-    {
-      sciSetText( ppsubwin->mon_x_label, &legx , 1, 1 ) ;
-    }
-
-    /*   legy=strtok_r((char *)0,"@",&buff); */
-    legy=strtok((char *)NULL,"@"); /* NULL to begin at the last read character */
-    if ( legy != NULL )
-    {
-      sciSetText( ppsubwin->mon_y_label, &legy , 1, 1 ) ;
-    }
-
-    /*   legz=strtok_r((char *)0,"@",&buff); */
-    legz=strtok((char *)NULL,"@");
-    if ( legz != NULL )
-    {
-      sciSetText( ppsubwin->mon_z_label, &legz , 1, 1 ) ;
-    }
-  }
-
-  /* Force psubwin->logflags to linear */
-  sciSetLogFlags(psubwin, linLogFlags);
-
-
-  pSUBWIN_FEATURE (psubwin)->axes.flag[0] = iflag[0]; /* mode: treatment of hidden parts */
-  if (iflag[1] != 0){
-    if (iflag[1]<7)
-      pSUBWIN_FEATURE (psubwin)->axes.flag[1] = iflag[1]; /* type: scaling (no more useful)  */
-    else
-      pSUBWIN_FEATURE (psubwin)->axes.flag[1] = iflag[1]-6; /* type: scaling (no more useful)  */
-  }
-
-  if( pSUBWIN_FEATURE (psubwin)->FirstPlot == FALSE && (iflag[2] == 0 || iflag[2] == 1))
-  {
-    /* Nothing to do: we leave as before */
-  }
-  else
-  {
-    pSUBWIN_FEATURE (psubwin)->axes.flag[2] = iflag[2]; /* box: frame around the plot      */
-
-    if(iflag[2] == 0 || iflag[2] == 1)
-    {
-
-      if (pSUBWIN_FEATURE(psubwin)->FirstPlot)
-      {
-       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
-       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
-       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
-       pSUBWIN_FEATURE (psubwin)->axes.rect = BT_OFF ;
-
-        sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,FALSE);
-        sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,FALSE);
-        sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,FALSE);
-      }
-      /*else no changes : the axes visible properties are driven by the previous plot */
-    }
-    else if(iflag[2] == 2)
-    {
-      pSUBWIN_FEATURE (psubwin)->axes.rect = BT_HIDDEN_AXIS ; /* for 2d use only (when switching to 2d mode) */
-
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
-
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,FALSE);
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,FALSE);
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,FALSE);
-    }
-    else if(iflag[2] == 3)
-    {
-      pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON ; /* for 2d use only (when switching to 2d mode) */
-
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
-
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,TRUE);
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,TRUE);
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,TRUE);
-    }
-    else if(iflag[2] == 4)
-    {
-      pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON ;
-
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = TRUE;
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = TRUE;
-      pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = TRUE;
-
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,TRUE);
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,TRUE);
-      sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,TRUE);
-    }
-  }
-
-  pSUBWIN_FEATURE (psubwin)->alpha  = *alpha;
-  pSUBWIN_FEATURE (psubwin)->theta  = *theta;
-
-  if ((sciGetGraphicMode (psubwin)->autoscaling)) {
-    /* compute and merge new specified bounds with psubwin->Srect */
-    switch (iflag[1])  {
-    case 0:  /* do not change psubwin->Srect */
-      break;
-    case 1 : case 3 : case 5 : case 7 : /* Force psubwin->Srect=ebox */
-      drect[0] = ebox[0]; /*xmin*/
-      drect[2] = ebox[2]; /*ymin*/
-      drect[1] = ebox[1]; /*xmax*/
-      drect[3] = ebox[3]; /*ymax*/
-      drect[4] = ebox[4]; /*zmin*/
-      drect[5] = ebox[5]; /*zmax*/
-      break;
-    case 2 : case 4 : case 6 : case 8:/* Force psubwin->Srect to the x and y bounds */
-      mn=(*m1) * (*n1);
-      drect[0] = (double) Mini(x, mn); /*xmin*/
-      drect[1] = (double) Maxi(x, mn); /*xmax*/
-      mn=(*m2) * (*n2);
-      drect[2] = (double) Mini(y, mn); /*ymin*/
-      drect[3] = (double) Maxi(y, mn); /*ymax*/
-      mn=(*m3) * (*n3);
-      drect[4] = (double) Mini(z, mn); /*zmin*/
-      drect[5] = (double) Maxi(z, mn); /*zmax*/
-      break;
-    }
-    if (!pSUBWIN_FEATURE(psubwin)->FirstPlot ) { /* merge psubwin->Srect and drect */
-      drect[0] = Min(pSUBWIN_FEATURE(psubwin)->SRect[0],drect[0]); /*xmin*/
-      drect[1] = Max(pSUBWIN_FEATURE(psubwin)->SRect[1],drect[1]); /*xmax*/
-      drect[2] = Min(pSUBWIN_FEATURE(psubwin)->SRect[2],drect[2]); /*ymin*/
-      drect[3] = Max(pSUBWIN_FEATURE(psubwin)->SRect[3],drect[3]); /*ymax*/
-      drect[4] = Min(pSUBWIN_FEATURE(psubwin)->SRect[4],drect[4]); /*zmin*/
-      drect[5] = Max(pSUBWIN_FEATURE(psubwin)->SRect[5],drect[5]); /*zmax*/
-    }
-    if (iflag[1] != 0)
-      bounds_changed = update_specification_bounds(psubwin, drect,3);
-  }
-
-  if(iflag[1] != 0)
-    pSUBWIN_FEATURE(psubwin)->isoview = (BOOL)( iflag[1] == 3 || iflag[1] == 4 ||
-                                               iflag[1] == 5 || iflag[1] == 6);
-
-  /* =================================================
-   * Analyze arguments to find entity type
-   * ================================================= */
-
-  if (*isfac== 1) {
-    if (*izcol == 0) {
-      if (strcmp(fname,"plot3d1")==0) {typeof3d = SCI_FAC3D;   flagcolor=1;}
-      else                               {typeof3d = SCI_FAC3D;   flagcolor=0;}
-    }
-    else if (*izcol == 2)                {typeof3d = SCI_FAC3D;   flagcolor=3;}
-    else                                 {typeof3d = SCI_FAC3D;   flagcolor=2;}
-  }
-  else  if  (*isfac== 0) {
-    if (strcmp(fname,"plot3d1")==0)   {typeof3d = SCI_PLOT3D;  flagcolor=1;}
-    else                                 {typeof3d = SCI_PLOT3D;  flagcolor=0;}
-  }
-  else                                   {typeof3d = SCI_PARAM3D1;flagcolor=1;}
-
-
-  /* =================================================
-   * Construct the Entities
-   * ================================================= */
-
-  if ( typeof3d != SCI_PARAM3D1 ) {/*Distinction here between SCI_PARAM3D1 and others*/
-
-
-    if ( *isfac == 1 )
-    {
-      /* x is considered as a matrix */
-      dimvectx = -1 ;
-    }
-    else if ( *m1 == 1 ) /* x is a row vector */
-    {
-      dimvectx = *n1;
-    }
-    else if ( *n1 == 1 ) /* x is a column vector */
-    {
-      dimvectx = *m1;
-    }
-    else /* x is a matrix */
-    {
-      dimvectx = -1;
-    }
-
-    if ( dimvectx > 1 )
-    {
-      int monotony = checkMonotony( x, dimvectx ) ;
-      if ( monotony == 0 )
-      {
-        endFigureDataWriting(parentFigure);
-        Scierror(999, _("%s: x vector is not monotonous.\n"),"Objplot3d");
-        return;
-      }
-
-      flag_x = monotony ;
-    }
-
-    if ( *isfac == 1 )
-    {
-      /* y is considered as a matrix */
-      dimvecty = -1 ;
-    }
-    else if ( *m2 == 1 ) /* y is a row vector */
-    {
-      dimvecty = *n2 ;
-    }
-    else if ( *n2 == 1 ) /* y is a column vector */
-    {
-      dimvecty = *m2 ;
-    }
-    else /* y is a matrix */
-    {
-      dimvecty = -1 ;
-    }
-
-    if( dimvecty > 1 )
-    {
-      /* test the monotony on y*/
-      int monotony = checkMonotony( y, dimvecty ) ;
-      if ( monotony == 0 )
-      {
-        endFigureDataWriting(parentFigure);
-        Scierror(999, _("%s: x vector is not monotonous.\n"),"Objplot3d");
-        return ;
-      }
-
-      flag_y = monotony ;
-    }
-
-    pNewSurface = ConstructSurface( psubwin, typeof3d,
-                                    x, y, z, zcol, *izcol, *m, *n, iflag,ebox,flagcolor,
-                                    isfac,m1,n1,m2,n2,m3,n3,m3n,n3n) ;
+       /* Force psubwin->logflags to linear */
+       sciSetLogFlags(psubwin, linLogFlags);
 
-    if ( pNewSurface == NULL )
-    {
-      endFigureDataWriting(parentFigure);
-      return ;
-    }
-
-    sciSetCurrentObj( pNewSurface ) ;
-
-    pSURFACE_FEATURE (pNewSurface)->flag_x = flag_x;
-    pSURFACE_FEATURE (pNewSurface)->flag_y = flag_y;
-
-    /* Force clipping */
-    sciSetIsClipping(pNewSurface, 0);  /* clipgrf */
 
+       pSUBWIN_FEATURE (psubwin)->axes.flag[0] = iflag[0]; /* mode: treatment of hidden parts */
+       if (iflag[1] != 0){
+               if (iflag[1]<7)
+                       pSUBWIN_FEATURE (psubwin)->axes.flag[1] = iflag[1]; /* type: scaling (no more useful)  */
+               else
+                       pSUBWIN_FEATURE (psubwin)->axes.flag[1] = iflag[1]-6; /* type: scaling (no more useful)  */
+       }
 
-  }
-  else
-    {
-      if ((hdltab = MALLOC (*n * sizeof (long))) == NULL) {
-        endFigureDataWriting(parentFigure);
-       Scierror(999,"%s: No more memory.\n",fname);
-       return;
-      }
-      for (i = 0; i < *n; ++i) {
-       /* F.Leray Pb here: In fact we do not create a Surface but one or several 3D Polylines
-          Pb comes when wanting to access the fields "surface_color" or "flag" for example
-          in function sciSet (cf. matdes.c).
-          Question 1: Are these properties accessible from a SCI_PARAM3D1 ?
-          Question 2: Is "flag" obsolete and replaced by "color_mode"?*/
-
-       if ((*n > 0) && (zcol != (double *)NULL)) {
-         if ((int) zcol[i] > 0){
-           int intzcol = (int) zcol[i];
-           sciSetCurrentObj (ConstructPolyline
-                             (sciGetCurrentSubWin(),
-                              &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
-                              &intzcol,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE));
-         }
-         else {
-           int intzcol = (int) -zcol[i];
-           sciSetCurrentObj (ConstructPolyline
-                             (sciGetCurrentSubWin(),
-                              &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
-                              NULL,NULL,&intzcol,NULL,NULL,FALSE,FALSE,TRUE,FALSE));
-         }
+       if( pSUBWIN_FEATURE (psubwin)->FirstPlot == FALSE && (iflag[2] == 0 || iflag[2] == 1))
+       {
+               /* Nothing to do: we leave as before */
        }
-       else { /* default case, nothing is given */
-         int curcolor = sciGetForeground(sciGetCurrentSubWin()); /* current color equivalent for new graphics mode */
-         sciSetCurrentObj (ConstructPolyline
-                           (sciGetCurrentSubWin(),
-                            &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
-                            &curcolor,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE));
+       else
+       {
+               pSUBWIN_FEATURE (psubwin)->axes.flag[2] = iflag[2]; /* box: frame around the plot      */
+
+               if(iflag[2] == 0 || iflag[2] == 1)
+               {
+
+                       if (pSUBWIN_FEATURE(psubwin)->FirstPlot)
+                       {
+                               pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
+                               pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
+                               pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
+                               pSUBWIN_FEATURE (psubwin)->axes.rect = BT_OFF ;
+
+                               sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,FALSE);
+                               sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,FALSE);
+                               sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,FALSE);
+                       }
+                       /*else no changes : the axes visible properties are driven by the previous plot */
+               }
+               else if(iflag[2] == 2)
+               {
+                       pSUBWIN_FEATURE (psubwin)->axes.rect = BT_HIDDEN_AXIS ; /* for 2d use only (when switching to 2d mode) */
+
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
+
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,FALSE);
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,FALSE);
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,FALSE);
+               }
+               else if(iflag[2] == 3)
+               {
+                       pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON ; /* for 2d use only (when switching to 2d mode) */
+
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = FALSE;
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = FALSE;
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = FALSE;
+
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,TRUE);
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,TRUE);
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,TRUE);
+               }
+               else if(iflag[2] == 4)
+               {
+                       pSUBWIN_FEATURE (psubwin)->axes.rect = BT_ON ;
+
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[0] = TRUE;
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[1] = TRUE;
+                       pSUBWIN_FEATURE (psubwin)->axes.axes_visible[2] = TRUE;
+
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_x_label,TRUE);
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_y_label,TRUE);
+                       sciSetVisibility(pSUBWIN_FEATURE (psubwin)->mon_z_label,TRUE);
+               }
        }
 
-       pobj = sciGetCurrentObj();
+       pSUBWIN_FEATURE (psubwin)->alpha  = *alpha;
+       pSUBWIN_FEATURE (psubwin)->theta  = *theta;
+
+       if ((sciGetGraphicMode (psubwin)->autoscaling)) {
+               /* compute and merge new specified bounds with psubwin->Srect */
+               switch (iflag[1])  {
+               case 0:  /* do not change psubwin->Srect */
+                       break;
+               case 1 : case 3 : case 5 : case 7 : /* Force psubwin->Srect=ebox */
+                       drect[0] = ebox[0]; /*xmin*/
+                       drect[2] = ebox[2]; /*ymin*/
+                       drect[1] = ebox[1]; /*xmax*/
+                       drect[3] = ebox[3]; /*ymax*/
+                       drect[4] = ebox[4]; /*zmin*/
+                       drect[5] = ebox[5]; /*zmax*/
+                       break;
+               case 2 : case 4 : case 6 : case 8:/* Force psubwin->Srect to the x and y bounds */
+                       getDrect(x, (*m1) * (*n1), &drect[0], &drect[1],
+                                            pSUBWIN_FEATURE(psubwin)->SRect[0], pSUBWIN_FEATURE(psubwin)->SRect[1]);
+
+                       getDrect(y, (*m2) * (*n2), &drect[2], &drect[3],
+                                            pSUBWIN_FEATURE(psubwin)->SRect[2], pSUBWIN_FEATURE(psubwin)->SRect[3]);
+
+                       getDrect(z, (*m3) * (*n3), &drect[4], &drect[5],
+                                            pSUBWIN_FEATURE(psubwin)->SRect[4], pSUBWIN_FEATURE(psubwin)->SRect[5]);
+                       
+                       break;
+               }
+               if (!pSUBWIN_FEATURE(psubwin)->FirstPlot ) { /* merge psubwin->Srect and drect */
+                       drect[0] = Min(pSUBWIN_FEATURE(psubwin)->SRect[0],drect[0]); /*xmin*/
+                       drect[1] = Max(pSUBWIN_FEATURE(psubwin)->SRect[1],drect[1]); /*xmax*/
+                       drect[2] = Min(pSUBWIN_FEATURE(psubwin)->SRect[2],drect[2]); /*ymin*/
+                       drect[3] = Max(pSUBWIN_FEATURE(psubwin)->SRect[3],drect[3]); /*ymax*/
+                       drect[4] = Min(pSUBWIN_FEATURE(psubwin)->SRect[4],drect[4]); /*zmin*/
+                       drect[5] = Max(pSUBWIN_FEATURE(psubwin)->SRect[5],drect[5]); /*zmax*/
+               }
+               if (iflag[1] != 0)
+               {
+                       bounds_changed = update_specification_bounds(psubwin, drect,3);
+               }
+       }
 
-       hdltab[i]=sciGetHandle(pobj);
-      }
+       if(iflag[1] != 0)
+               pSUBWIN_FEATURE(psubwin)->isoview = (BOOL)( iflag[1] == 3 || iflag[1] == 4 ||
+               iflag[1] == 5 || iflag[1] == 6);
+
+       /* =================================================
+       * Analyze arguments to find entity type
+       * ================================================= */
+
+       if (*isfac== 1) {
+               if (*izcol == 0) {
+                       if (strcmp(fname,"plot3d1")==0) {typeof3d = SCI_FAC3D;   flagcolor=1;}
+                       else                               {typeof3d = SCI_FAC3D;   flagcolor=0;}
+               }
+               else if (*izcol == 2)                {typeof3d = SCI_FAC3D;   flagcolor=3;}
+               else                                 {typeof3d = SCI_FAC3D;   flagcolor=2;}
+       }
+       else  if  (*isfac== 0) {
+               if (strcmp(fname,"plot3d1")==0)   {typeof3d = SCI_PLOT3D;  flagcolor=1;}
+               else                                 {typeof3d = SCI_PLOT3D;  flagcolor=0;}
+       }
+       else                                   {typeof3d = SCI_PARAM3D1;flagcolor=1;}
+
+
+       /* =================================================
+       * Construct the Entities
+       * ================================================= */
+
+       if ( typeof3d != SCI_PARAM3D1 ) {/*Distinction here between SCI_PARAM3D1 and others*/
+
+
+               if ( *isfac == 1 )
+               {
+                       /* x is considered as a matrix */
+                       dimvectx = -1 ;
+               }
+               else if ( *m1 == 1 ) /* x is a row vector */
+               {
+                       dimvectx = *n1;
+               }
+               else if ( *n1 == 1 ) /* x is a column vector */
+               {
+                       dimvectx = *m1;
+               }
+               else /* x is a matrix */
+               {
+                       dimvectx = -1;
+               }
+
+               if ( dimvectx > 1 )
+               {
+                       int monotony = checkMonotony( x, dimvectx ) ;
+                       if ( monotony == 0 )
+                       {
+                               endFigureDataWriting(parentFigure);
+                               Scierror(999, _("%s: x vector is not monotonous.\n"),"Objplot3d");
+                               return;
+                       }
+
+                       flag_x = monotony ;
+               }
+
+               if ( *isfac == 1 )
+               {
+                       /* y is considered as a matrix */
+                       dimvecty = -1 ;
+               }
+               else if ( *m2 == 1 ) /* y is a row vector */
+               {
+                       dimvecty = *n2 ;
+               }
+               else if ( *n2 == 1 ) /* y is a column vector */
+               {
+                       dimvecty = *m2 ;
+               }
+               else /* y is a matrix */
+               {
+                       dimvecty = -1 ;
+               }
+
+               if( dimvecty > 1 )
+               {
+                       /* test the monotony on y*/
+                       int monotony = checkMonotony( y, dimvecty ) ;
+                       if ( monotony == 0 )
+                       {
+                               endFigureDataWriting(parentFigure);
+                               Scierror(999, _("%s: x vector is not monotonous.\n"),"Objplot3d");
+                               return ;
+                       }
+
+                       flag_y = monotony ;
+               }
+
+               pNewSurface = ConstructSurface( psubwin, typeof3d,
+                       x, y, z, zcol, *izcol, *m, *n, iflag,ebox,flagcolor,
+                       isfac,m1,n1,m2,n2,m3,n3,m3n,n3n) ;
+
+               if ( pNewSurface == NULL )
+               {
+                       endFigureDataWriting(parentFigure);
+                       return ;
+               }
+
+               sciSetCurrentObj( pNewSurface ) ;
+
+               pSURFACE_FEATURE (pNewSurface)->flag_x = flag_x;
+               pSURFACE_FEATURE (pNewSurface)->flag_y = flag_y;
+
+               /* Force clipping */
+               sciSetIsClipping(pNewSurface, 0);  /* clipgrf */
 
 
-      /** construct Compound and make it current object**/
-      if ( *n>1 ) sciSetCurrentObj (ConstructCompound (hdltab, *n));
-      FREE(hdltab);
-    }
+       }
+       else
+       {
+               if ((hdltab = MALLOC (*n * sizeof (long))) == NULL) {
+                       endFigureDataWriting(parentFigure);
+                       Scierror(999,"%s: No more memory.\n",fname);
+                       return;
+               }
+               for (i = 0; i < *n; ++i) {
+                       /* F.Leray Pb here: In fact we do not create a Surface but one or several 3D Polylines
+                       Pb comes when wanting to access the fields "surface_color" or "flag" for example
+                       in function sciSet (cf. matdes.c).
+                       Question 1: Are these properties accessible from a SCI_PARAM3D1 ?
+                       Question 2: Is "flag" obsolete and replaced by "color_mode"?*/
+
+                       if ((*n > 0) && (zcol != (double *)NULL)) {
+                               if ((int) zcol[i] > 0){
+                                       int intzcol = (int) zcol[i];
+                                       sciSetCurrentObj (ConstructPolyline
+                                               (sciGetCurrentSubWin(),
+                                               &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
+                                               &intzcol,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE));
+                               }
+                               else {
+                                       int intzcol = (int) -zcol[i];
+                                       sciSetCurrentObj (ConstructPolyline
+                                               (sciGetCurrentSubWin(),
+                                               &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
+                                               NULL,NULL,&intzcol,NULL,NULL,FALSE,FALSE,TRUE,FALSE));
+                               }
+                       }
+                       else { /* default case, nothing is given */
+                               int curcolor = sciGetForeground(sciGetCurrentSubWin()); /* current color equivalent for new graphics mode */
+                               sciSetCurrentObj (ConstructPolyline
+                                       (sciGetCurrentSubWin(),
+                                       &(x[*m * i]),&(y[*m * i]),&(z[*m * i]),0,*m,1,
+                                       &curcolor,NULL,NULL,NULL,NULL,TRUE,FALSE,FALSE,FALSE));
+                       }
+
+                       pobj = sciGetCurrentObj();
+
+                       hdltab[i]=sciGetHandle(pobj);
+               }
+
+
+               /** construct Compound and make it current object**/
+               if ( *n>1 ) sciSetCurrentObj (ConstructCompound (hdltab, *n));
+               FREE(hdltab);
+       }
 
-  /* =================================================
-   * Redraw Figure
-   * ================================================= */
-  // subwin has been modified
-  forceRedraw(psubwin);
-  endFigureDataWriting(parentFigure);
-  sciDrawObj(sciGetCurrentFigure ());
+       /* =================================================
+       * Redraw Figure
+       * ================================================= */
+       // subwin has been modified
+       forceRedraw(psubwin);
+       endFigureDataWriting(parentFigure);
+       sciDrawObj(sciGetCurrentFigure ());
 
-  pSUBWIN_FEATURE(psubwin)->FirstPlot=FALSE;
+       pSUBWIN_FEATURE(psubwin)->FirstPlot=FALSE;
 
-  FREE(loc); loc = NULL;
+       FREE(loc); loc = NULL;
 
 }
 /*-----------------------------------------------------------
@@ -808,3 +818,20 @@ void Objfec ( double    x[]        ,
   C2F(fec)(x,y,noeud,fun,n,m,strflag,legend,brect,aaint,
           Zminmax,Colminmax,ColOut,WithMesh,flagNax,4L,bsiz);
 }
+/*------------------------------------------------------------------------*/
+static void getDrect(const double vector[], int nbElements,
+                                                                                double * dMin, double * dMax,
+                                                                                double defaultMin, double defaultMax)
+{
+       if (containsOneFiniteElement(vector, nbElements))
+       {
+               *dMin = Mini(vector, nbElements);
+               *dMax = Maxi(vector, nbElements);
+       }
+       else
+       {
+               *dMin = defaultMin;
+               *dMax = defaultMax;
+       }
+}
+/*------------------------------------------------------------------------*/
\ No newline at end of file
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_2540.dia.ref b/scilab/modules/graphics/tests/nonreg_tests/bug_2540.dia.ref
new file mode 100644 (file)
index 0000000..fb6b053
--- /dev/null
@@ -0,0 +1,24 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009-2009 - Digiteo - Jean-Baptiste Silvy
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+// <-- Non-regression test for bug 2540 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=2540
+//
+// <-- Short Description -->
+// plot3d hangs scilab when plotting a matrix full with NaN
+//
+dummy = ones(10,10);
+dummy2 = dummy*%nan;
+plot3d(1:10,1:10,dummy2);
+clf();
+plot3d(1:10,1:10,dummy2);
+// this also crashed scilab
+e = gce();
+e.data.z(1,1) = 1;
+e.mark_mode = "on";
diff --git a/scilab/modules/graphics/tests/nonreg_tests/bug_2540.tst b/scilab/modules/graphics/tests/nonreg_tests/bug_2540.tst
new file mode 100644 (file)
index 0000000..372bce5
--- /dev/null
@@ -0,0 +1,28 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2009-2009 - Digiteo - Jean-Baptiste Silvy
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- TEST WITH GRAPHIC -->
+
+// <-- Non-regression test for bug 2540 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=2540
+//
+// <-- Short Description -->
+// plot3d hangs scilab when plotting a matrix full with NaN
+// 
+
+dummy = ones(10,10);
+dummy2 = dummy*%nan;
+plot3d(1:10,1:10,dummy2);
+clf();
+plot3d(1:10,1:10,dummy2); 
+
+// this also crashed scilab
+e = gce();
+e.data.z(1,1) = 1;
+e.mark_mode = "on";
index 5195235..ed33db2 100644 (file)
@@ -35,6 +35,8 @@ public abstract class MarkDrawerGL extends DrawableObjectGL {
        
        private Vector3D[] markPos;
        
+       private int nbMarks;
+       
        /**
         * Default Constructor
         */
@@ -42,6 +44,7 @@ public abstract class MarkDrawerGL extends DrawableObjectGL {
                super();
                drawer = new MarkDrawer();
                markPos = null;
+               nbMarks = 0;
        }
        
        
@@ -163,17 +166,20 @@ public abstract class MarkDrawerGL extends DrawableObjectGL {
                
                CoordinateTransformation transform = getCoordinateTransformation();
                
-               // need to perform this befaore swithching to pixel coordinates
-               Vector3D[] pixCoords = transform.getCanvasCoordinates(gl, markPos);
+               // need to perform this before switching to pixel coordinates
+               Vector3D[] pixCoords = new Vector3D[nbMarks];
+               for (int i = 0; i < nbMarks; i++) {
+                       pixCoords[i] = transform.getCanvasCoordinates(gl, markPos[i]);
+               }
                
                // switch to pixel coordinates
                GLTools.usePixelCoordinates(gl, getParentFigureGL());
                
                // create the display list using pixel coordinates
                startRecordDL();
-               // mark are drawn with a line width of 1.
+               // marks are drawn with a line width of 1.
                gl.glLineWidth(1.0f);
-               for (int i = 0; i < markPos.length; i++) {
+               for (int i = 0; i < nbMarks; i++) {
                        // switch back to the new frame
                        getDrawer().drawMark(pixCoords[i].getX(), pixCoords[i].getY(), pixCoords[i].getZ());
                }
@@ -185,7 +191,7 @@ public abstract class MarkDrawerGL extends DrawableObjectGL {
        }
        
        /**
-        * Show the compute ddisplay list
+        * Show the compute display list
         */
        public void showMarks() {
                GL gl = getGL();
@@ -202,8 +208,18 @@ public abstract class MarkDrawerGL extends DrawableObjectGL {
         * @param marksPosition positions in 3D of marks
         */
        public void drawMarks(Vector3D[] marksPosition) {
+               drawMarks(marksPosition, marksPosition.length);
+       }
+       
+       /**
+        * Display the marks at the positions specified by marksPosition
+        * @param marksPosition positions in 3D of marks
+        * @param nbMarks number of marks to display
+        */
+       public void drawMarks(Vector3D[] marksPosition, int nbMarks) {
                this.markPos = marksPosition;
-               // mark object has chnaged, we mey need to recreate the display list
+               this.nbMarks = nbMarks;
+               // mark object has changed, we may need to recreate the display list
                getDrawer().createDisplayList();
                redrawMarks();
        }
index 8c994d2..1074a8f 100644 (file)
@@ -68,7 +68,6 @@ public class SurfaceMarkDrawerGL extends MarkDrawerGL {
         * @param nbVertices number of vertices for each facet
         */
        public void drawSurface(double[] xCoords, double[] yCoords, double[] zCoords, int nbVertices) {
-       
                decomposer.setFacetsPositions(xCoords, yCoords, zCoords, nbVertices);
                
                // create a new array of marks positions
@@ -79,14 +78,16 @@ public class SurfaceMarkDrawerGL extends MarkDrawerGL {
                        // find positions of the facet vertices
                        Vector3D[] curFacetPos = decomposer.next();
                        
-                       // copy the found values into the array of mark positions
-                       for (int i = 0; i < curFacetPos.length; i++) {
-                               marksPos[markIndex] = curFacetPos[i];
-                               markIndex++;
+                       if (curFacetPos != null) {
+                               // copy the found values into the array of mark positions
+                               for (int i = 0; i < curFacetPos.length; i++) {
+                                       marksPos[markIndex] = curFacetPos[i];
+                                       markIndex++;
+                               }
                        }
                }
                
-               drawMarks(marksPos);
+               drawMarks(marksPos, markIndex);
                
                // decomposer is no longer needed, we got the array of marks positions
                decomposer = null;
index 1afcb66..1412a77 100644 (file)
@@ -29,6 +29,10 @@ public class SciTextRenderer {
 
        private static final float EPSILON = 1.0e-4f; 
 
+       private static boolean areMipmapsAvailable;
+       
+       private static boolean areMMsAvailableUpToDate;
+       
        /** Size of the font to use */
        private float fontSize;
        
@@ -40,10 +44,6 @@ public class SciTextRenderer {
        
        private boolean useFractionalMetrics;
        
-       private static boolean areMipmapsAvailable;
-       
-       private static boolean areMMsAvailableUpToDate;
-       
        /**
         * Constructor from a Font to use.
         * @param fontSize font Size of the font