~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to routines/graphics/Contour.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*------------------------------------------------------------------------
2
2
 *    Graphic library
3
 
 *    Copyright (C) 1998-2000 Enpc/Jean-Philippe Chancelier
4
 
 *    jpc@cereve.enpc.fr 
 
3
 *    Copyright (C) 1998-2001 Enpc/Jean-Philippe Chancelier
 
4
 *    jpc@cermics.enpc.fr 
5
5
 --------------------------------------------------------------------------*/
6
6
 
7
7
#include <string.h> /* in case of dbmalloc use */
9
9
#include <math.h>
10
10
#include "Math.h"
11
11
#include "PloEch.h"
 
12
#include "Entities.h" /* F.Leray 21.04.04 : for update_2dbounds call*/
 
13
/*extern void compute_data_bounds(int cflag,char dataflag,double *x,double *y,int n1,int n2,double *drect);*/
 
14
extern void compute_data_bounds2(int cflag,char dataflag,char *logflags,double *x,double *y,int n1,int n2,double *drect);
 
15
extern void update_specification_bounds(sciPointObj *psubwin, double *rect,int flag);
 
16
extern int re_index_brect(double * brect, double * drect);
 
17
extern void strflag2axes_properties(sciPointObj * psubwin, char * strflag);
12
18
 
13
19
typedef void (level_f) __PARAMS((integer ival, double Cont, double xncont,
14
20
                               double yncont));
61
67
static double *GX,*GY,*GZ;
62
68
static integer Gn1,Gn2;
63
69
 
64
 
static void InitValues(x, y, z, n1, n2)
65
 
     double *x,*y,*z;
66
 
     integer n1,n2;
 
70
static void InitValues(double *x, double *y, double *z, integer n1, integer n2)
67
71
{
68
72
  Gn1=n1;  Gn2=n2;  GX = x;  GY = y;  GZ = z;
69
73
}
70
74
 
71
75
/*--------return the  value of f for a pointeger on the grid-----*/
72
76
 
73
 
static double phi_cont(i, j)
74
 
     integer i,j;
 
77
static double phi_cont(integer i, integer j)
75
78
{
76
79
  return(GZ[i+Gn1*j]);
77
80
}
79
82
/*---------return the coordinates between  [xi,xj] along one axis 
80
83
 *  for which the value of f is zCont */ 
81
84
 
82
 
static double f_intercept(zCont, fi, xi, fj, xj)
83
 
     double zCont,fi,xi,fj,xj;
 
85
static double f_intercept(double zCont, double fi, double xi, double fj, double xj)
84
86
{
85
87
  return( xi+ (zCont-fi)*(xj-xi)/ (fj-fi));
86
88
}
87
89
 
88
90
/* check for boundary points */
89
91
 
90
 
static integer  bdyp(i, j)
91
 
     integer i,j;
 
92
static integer  bdyp(integer i, integer j)
92
93
{
93
94
  return (  j == 0 || i == 0 || j == Gn2-1 || i == Gn1-1 );
94
95
}
97
98
 
98
99
static  integer *itg_cont, *xbd_cont,*ybd_cont;
99
100
 
100
 
static integer get_itg_cont(i, j)
101
 
     integer i,j;
 
101
static integer get_itg_cont(integer i, integer j)
102
102
{
103
103
  return( itg_cont[i+Gn1*j]);
104
104
}
105
105
 
106
 
static void inc_itg_cont(i, j, val)
107
 
     integer i,j, val;
 
106
static void inc_itg_cont(integer i, integer j, integer val)
108
107
{
109
108
  itg_cont[i+Gn1*j] += val;
110
109
}
111
110
 
112
 
static integer not_same_sign(val1, val2)
113
 
     double val1;
114
 
     double val2;
 
111
static integer not_same_sign(double val1, double val2)
115
112
{
116
113
  if ( ISNAN(val1) ==1 || ISNAN(val2) == 1) return(0);
117
114
  /** 0.0 est consid\'er\'e comme positif **/
123
120
      if ( val2 >= 0.0) return(1) ; else return(0);}
124
121
}
125
122
 
126
 
static integer oddp(i) integer i; { return( i == 1 || i ==3 );}
 
123
static integer oddp(integer i) { return( i == 1 || i ==3 );}
127
124
 
128
125
/*---------return the x-value of a grid point--------*/
129
126
 
130
 
static double x_cont(i) integer i; {  return GX[i] ;}
 
127
static double x_cont(integer i) {  return GX[i] ;}
131
128
 
132
129
/*---------return the y-value of a grid point --------*/
133
130
 
134
 
static double y_cont(i) integer i; {  return GY[i] ;}
 
131
static double y_cont(integer i) {  return GY[i] ;}
135
132
 
136
133
/*------------------------------------------------------------
137
134
 * Draw level curves for a function f(x,y) which values 
151
148
static double ZC=0.0;
152
149
static char   ContNumFormat[100];
153
150
 
154
 
int C2F(contour)(x,y,z,n1,n2,flagnz,nz,zz,teta,alpha,legend,flag,bbox,zlev,lstr)
155
 
     double *teta,*alpha;
156
 
     integer flag[3];
157
 
     char legend[];
158
 
     double x[],y[],z[],zz[],bbox[6],*zlev;
159
 
     integer *n1,*n2,*nz,*flagnz;
160
 
     integer lstr;
 
151
int C2F(contour)(double *x, double *y, double *z, integer *n1, integer *n2, integer *flagnz, integer *nz, double *zz, double *teta, double *alpha, char *legend, integer *flag, double *bbox, double *zlev, integer lstr)
161
152
{
162
153
  int err=0;
163
154
  integer verbose=0,narg,fg;
252
243
 
253
244
/** interface for contour2d **/
254
245
 
255
 
int C2F(contour2)(x,y,z,n1,n2,flagnz,nz,zz,style,strflag,legend,brect,aaint,lstr1,lstr2)
256
 
     double x[],y[],z[],zz[];
257
 
     integer *n1,*n2,*nz,*flagnz;
258
 
     double brect[];
259
 
     integer aaint[];
260
 
     char legend[],strflag[];
261
 
     integer lstr1,lstr2,style[];
 
246
int C2F(contour2)(double *x, double *y, double *z, integer *n1, integer *n2, integer *flagnz, integer *nz, double *zz, integer *style, char *strflag, char *legend, double *brect, integer *aaint, integer lstr1, integer lstr2)
262
247
{
263
248
  Contour2D(ContStore2,"contour2",x,y,z,n1,n2,flagnz,nz,zz,style,strflag,
264
249
            legend,brect,aaint,lstr1,lstr2);
268
253
/* interface for contour2di used in macro contourf 
269
254
 * used when we want to get the values which constitues the contour inside Scilab 
270
255
 * contour2di + c2dex 
 
256
 * THIS PROCEDURE IS NO LONGUER USED 
271
257
 */
272
258
 
273
 
static int Contour2D(func,name,x,y,z,n1,n2,flagnz,nz,zz,style,strflag,legend,brect,aaint,lstr1,lstr2)
274
 
     ptr_level_f func;
275
 
     char name[];
276
 
     double x[],y[],z[],zz[];
277
 
     integer *n1,*n2,*nz,*flagnz;
278
 
     double brect[];
279
 
     integer aaint[];
280
 
     char legend[],strflag[];
281
 
     integer lstr1,lstr2,style[];
 
259
static int Contour2D(ptr_level_f func, char *name, double *x, double *y, double *z, integer *n1, integer *n2, integer *flagnz, integer *nz, double *zz, integer *style, char *strflag, char *legend, double *brect, integer *aaint, integer lstr1, integer lstr2)
282
260
{
283
261
  integer err=0;
284
262
  static double *zconst;
285
263
  double zmin,zmax;
286
264
  integer N[3],i;
 
265
  double drect[6];
 
266
  sciPointObj * psubwin = NULL;  /* Adding F.Leray 22.04.04 */
287
267
 
288
268
  /** Boundaries of the frame **/
289
 
  update_frame_bounds(1,"gnn",x,y,n1,n2,aaint,strflag,brect);
290
 
 
 
269
  if(version_flag() != 0)
 
270
    update_frame_bounds(1,"gnn",x,y,n1,n2,aaint,strflag,brect);
 
271
  else /* F.Leray 21.04.04 */
 
272
    {
 
273
      psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ());
 
274
      
 
275
      /* Force psubwin->is3d to FALSE: we are in 2D mode */
 
276
      if (sciGetSurface(psubwin) == (sciPointObj *) NULL)
 
277
        {
 
278
          pSUBWIN_FEATURE (psubwin)->is3d = FALSE;
 
279
          pSUBWIN_FEATURE (psubwin)->project[2]= 0;
 
280
        }
 
281
      pSUBWIN_FEATURE (psubwin)->theta_kp=pSUBWIN_FEATURE (psubwin)->theta;
 
282
      pSUBWIN_FEATURE (psubwin)->alpha_kp=pSUBWIN_FEATURE (psubwin)->alpha;  
 
283
      pSUBWIN_FEATURE (psubwin)->alpha  = 0.0;
 
284
      pSUBWIN_FEATURE (psubwin)->theta  = 270.0;
 
285
      
 
286
      for (i=0;i<4;i++) pSUBWIN_FEATURE(psubwin)->axes.aaint[i] = aaint[i]; 
 
287
      if (sciGetGraphicMode (psubwin)->autoscaling) {
 
288
        /* compute and merge new specified bounds with psubwin->Srect */
 
289
        switch (strflag[1])  {
 
290
        case '0': 
 
291
          /* do not change psubwin->Srect */
 
292
          break;
 
293
        case '1' : case '3' : case '5' : case '7':
 
294
          /* Force psubwin->Srect=brect */
 
295
          re_index_brect(brect,drect);
 
296
          break;
 
297
        case '2' : case '4' : case '6' : case '8':
 
298
          /* Force psubwin->Srect to the x and y bounds */
 
299
         /*  compute_data_bounds(1,'g',x,y,*n1,*n2,drect); */
 
300
          compute_data_bounds2(1,'g',pSUBWIN_FEATURE(psubwin)->logflags,x,y,*n1,*n2,drect);
 
301
          break;
 
302
        }
 
303
        if (!pSUBWIN_FEATURE(psubwin)->FirstPlot &&(strflag[1] == '7' || strflag[1] == '8')) { /* merge psubwin->Srect and drect */
 
304
          drect[0] = Min(pSUBWIN_FEATURE(psubwin)->SRect[0],drect[0]); /*xmin*/
 
305
          drect[2] = Min(pSUBWIN_FEATURE(psubwin)->SRect[2],drect[2]); /*ymin*/
 
306
          drect[1] = Max(pSUBWIN_FEATURE(psubwin)->SRect[1],drect[1]); /*xmax*/
 
307
          drect[3] = Max(pSUBWIN_FEATURE(psubwin)->SRect[3],drect[3]); /*ymax*/
 
308
        }
 
309
        if (strflag[1] != '0') update_specification_bounds(psubwin, drect,2);
 
310
      } 
 
311
      strflag2axes_properties(psubwin, strflag);
 
312
      pSUBWIN_FEATURE (psubwin)->FirstPlot = FALSE;
 
313
    }
 
314
  
291
315
  /** If Record is on **/
292
316
  if (GetDriver()=='R' && strcmp(name,"contour2")==0 ) 
293
317
    StoreContour2D("contour2",x,y,z,n1,n2,flagnz,nz,zz,style,strflag,legend,brect,aaint);
323
347
  return(0);
324
348
}
325
349
 
326
 
int C2F(contourif)(x,y,z,n1,n2,flagnz,nz,zz,style)
327
 
     double x[],y[],z[],zz[];
328
 
     integer *n1,*n2,*nz,*flagnz,style[];
 
350
int C2F(contourif)(double *x, double *y, double *z, integer *n1, integer *n2, integer *flagnz, integer *nz, double *zz, integer *style)
329
351
{
330
352
  integer err=0;
331
353
  static double *zconst;
365
387
 *  gives the dash style for contour i
366
388
 *-------------------------------------------------------*/
367
389
 
368
 
static void contourI(func, x, y, z, zCont, N,style, err)
369
 
     ptr_level_f func;
370
 
     double *x;
371
 
     double *y;
372
 
     double *z;
373
 
     double *zCont;
374
 
     integer *N,*style;
375
 
     integer *err;
 
390
static void contourI(ptr_level_f func, double *x, double *y, double *z, double *zCont, integer *N, integer *style, integer *err)
376
391
{
377
392
  int check = 1;
378
393
  char *F;
451
466
 *  c: indice of the contour Cont 
452
467
 *---------------------------------------------------------------------*/
453
468
 
454
 
static void look(func, i, j, ib, jb, qq, Cont,style)
455
 
     ptr_level_f func;
456
 
     integer i;
457
 
     integer j;
458
 
     integer ib;
459
 
     integer jb;
460
 
     integer qq;
461
 
     double Cont;
462
 
     integer style;
 
469
static void look(ptr_level_f func, integer i, integer j, integer ib, integer jb, integer qq, double Cont, integer style)
463
470
{
464
471
  integer ip,jp,im,jm,zds,ent=0,flag=0,wflag;
465
472
  jp= j+1; ip= i+1; jm=j-1;im=i-1;
596
603
 *       suivant a explorer 
597
604
 *-----------------------------------------------------------------------*/
598
605
 
599
 
static integer ffnd (func, i1, i2, i3, i4, jj1, jj2, jj3, jj4, ent, qq, Cont, zds)
600
 
     ptr_level_f func;
601
 
     integer i1,i2,i3,i4, jj1, jj2, jj3, jj4, ent, qq;
602
 
     double Cont;
603
 
     integer *zds;
 
606
static integer ffnd (ptr_level_f func, integer i1, integer i2, integer i3, integer i4, integer jj1, integer jj2, integer jj3, integer jj4, integer ent, integer qq, double Cont, integer *zds)
604
607
{
605
608
  double phi1,phi2,phi3,phi4,xav,yav,phiav;
606
609
  integer revflag,i;
672
675
 */
673
676
 
674
677
static void
675
 
G_ContStore(ival, xncont, yncont)
676
 
     integer ival;
677
 
     int xncont,yncont;
 
678
G_ContStore(integer ival, int xncont, int yncont)
678
679
{
679
680
  int n;
680
681
  /* nouveau contour */
695
696
 */
696
697
 
697
698
static void
698
 
ContStore(ival, Cont, xncont, yncont)
699
 
     integer ival;
700
 
     double Cont,xncont,yncont;
 
699
ContStore(integer ival, double Cont, double xncont, double yncont)
701
700
{
702
701
  G_ContStore(ival,GEOX(xncont,yncont,Cont),
703
702
              GEOY(xncont,yncont,Cont));
710
709
 */
711
710
 
712
711
static void
713
 
ContStore1(ival, Cont, xncont, yncont)
714
 
     integer ival;
715
 
     double Cont,xncont,yncont;
 
712
ContStore1(integer ival, double Cont, double xncont, double yncont)
716
713
{
717
714
  G_ContStore(ival,GEOX(xncont,yncont,ZC),
718
715
              GEOY(xncont,yncont,ZC));
725
722
 */
726
723
 
727
724
static void
728
 
ContStore2(ival, Cont, xncont, yncont)
729
 
     integer ival;
730
 
     double Cont,xncont,yncont;
 
725
ContStore2(integer ival, double Cont, double xncont, double yncont)
731
726
{
732
727
  G_ContStore(ival,XScale(xncont),YScale(yncont));
733
728
}
738
733
 * floating point format 
739
734
 */
740
735
 
741
 
static void ContourTrace(Cont,style)
742
 
     double Cont;
743
 
     integer style;
 
736
static void ContourTrace(double Cont, integer style)
744
737
745
738
  char *F;
746
739
  integer verbose=0 ,Dnarg,Dvalue[10];
783
776
 
784
777
/** used to bring back data to Scilab Stack **/
785
778
 
786
 
int C2F(getconts)(x,y,mm ,n)
787
 
     double **x,**y;
788
 
     integer *mm,*n;
 
779
int C2F(getconts)(double **x, double **y, integer *mm, integer *n)
789
780
{
790
781
  *x = Gxcont;
791
782
  *y = Gycont;
794
785
  return 0;
795
786
}
796
787
 
797
 
static void GContStore2(ival, Cont, xncont, yncont)
798
 
     integer ival;
799
 
     double Cont;
800
 
     double xncont;
801
 
     double yncont;
 
788
static void GContStore2(integer ival, double Cont, double xncont, double yncont)
802
789
{
803
790
  int n;
804
791
  if ( ival == 0) 
827
814
  count++;
828
815
}
829
816
 
830
 
static void GContStore2Last()
 
817
static void GContStore2Last(void)
831
818
{
832
819
  if ( last != -1 ) Gycont[last]= count;
833
820
}