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

« back to all changes in this revision

Viewing changes to routines/graphics/Plo3dn.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
/*------------------------------------------------------------------------
 
2
 *    Graphic library
 
3
 *    Copyright (C) 2003-2004 Inria/Djalel Abdemouche
 
4
 --------------------------------------------------------------------------*/
 
5
 
 
6
#include <string.h> 
 
7
#include <math.h>
 
8
#include <stdio.h>
 
9
#include "Math.h"
 
10
#include "PloEch.h"
 
11
#include "Entities.h"    
 
12
 
 
13
extern double C2F(dsort)();
 
14
/*-------------------------------------------------------------------------
 
15
 *   plo3dn function  ( 3D Plotting of surfaces given by z=f(x,y)  )
 
16
 *-------------------------------------------------------------------------*/
 
17
 
 
18
void C2F(plot3dn)(sciPointObj *pobj, double *x, double *y, double *z, integer *p, integer *q)
 
19
{
 
20
  static integer fg1,dc;
 
21
  integer polysize,npoly,whiteid,verbose=0,narg;
 
22
  integer *polyx,*polyy,*fill;
 
23
  static integer cache;
 
24
  static double zmin,zmax;
 
25
  integer i,j,flagcolor;  
 
26
  sciPointObj *psubwin;
 
27
 
 
28
  psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ()); 
 
29
 
 
30
  zmin  = pSUBWIN_FEATURE(psubwin)->SRect[4]; /*zmin*/
 
31
  zmax  = pSUBWIN_FEATURE(psubwin)->SRect[5]; /*zmax*/
 
32
  cache = pSUBWIN_FEATURE(psubwin)->hiddenstate;
 
33
 
 
34
  fg1       = pSURFACE_FEATURE (pobj)->hiddencolor;   
 
35
  dc        = pSURFACE_FEATURE (pobj)->flag[0];
 
36
  flagcolor = pSURFACE_FEATURE (pobj)->flagcolor;
 
37
 
 
38
   /** initialisation **/
 
39
  polyx = graphic_alloc(0,5*(*q),sizeof(int));
 
40
  polyy = graphic_alloc(1,5*(*q),sizeof(int));
 
41
  fill  = graphic_alloc(2,(*q),sizeof(int));
 
42
  if ( (polyx == NULL) || (polyy == NULL) || (fill  == NULL)) 
 
43
    {
 
44
      Scistring("plot3dg_ : malloc No more Place\n");
 
45
      return;
 
46
    }
 
47
 
 
48
 
 
49
  C2F(dr)("xget","lastpattern",&verbose,&whiteid,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
50
  /*  if (fg1<=0) fg1=dc;*/
 
51
  for ( i =0 ; i < (*q)-1 ; i++)   fill[i]= dc ;
 
52
  polysize=5;npoly= (*q)-1;
 
53
 
 
54
  /** The 3d plot **/
 
55
  /** Choix de l'ordre de parcourt **/
 
56
  switch (cache)
 
57
    {
 
58
    case 0 : 
 
59
      for ( i =0 ; i < (*p)-1 ; i++)
 
60
        {
 
61
          int npolyok=0;
 
62
          for ( j =0 ; j < (*q)-1 ; j++)
 
63
            {
 
64
             npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax,
 
65
                                x,y,z,i,j,npolyok,p,dc,fg1);
 
66
            }
 
67
          if ( npolyok != 0) 
 
68
            C2F(dr)("xliness","str",polyx,polyy,fill,&npolyok,&polysize
 
69
                    ,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
70
        }
 
71
      break;
 
72
    case 1 : 
 
73
      for ( i =0 ; i < (*p)-1 ; i++)
 
74
        {
 
75
          int npolyok=0;
 
76
          for ( j =0  ; j < (*q)-1  ; j++)
 
77
            {
 
78
              npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax,
 
79
                                 x,y,z,i,(*q)-2-j,npolyok,p,dc,fg1);
 
80
           }
 
81
          if ( npolyok != 0) 
 
82
            C2F(dr)("xliness","str",polyx,polyy,fill,&npolyok,&polysize
 
83
                    ,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
84
        }
 
85
      break;
 
86
    case 2 : 
 
87
      for ( i =(*p)-2 ; i >=0  ; i--)
 
88
        {
 
89
          int npolyok=0;
 
90
          for ( j = 0 ; j < (*q)-1 ; j++)
 
91
            {
 
92
             npolyok +=     (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax,
 
93
                                    x,y,z,i,(*q)-2-j,npolyok,p,dc,fg1);
 
94
           }
 
95
          if ( npolyok != 0) 
 
96
            C2F(dr)("xliness","str",polyx,polyy,fill,&npolyok,&polysize
 
97
                    ,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
98
        }
 
99
      break;
 
100
    case 3 : 
 
101
      for ( i =(*p)-2 ; i >=0  ; i--)
 
102
        {
 
103
          int npolyok=0;
 
104
          for ( j =0 ; j < (*q)-1 ; j++)
 
105
            {
 
106
             npolyok += (Gen3DPoints)(flagcolor,polyx,polyy,fill,whiteid,zmin,zmax,
 
107
                                x,y,z,i,j,npolyok,p,dc,fg1);
 
108
           }
 
109
          if ( npolyok != 0) 
 
110
            C2F(dr)("xliness","str",polyx,polyy,fill,&npolyok,&polysize
 
111
                    ,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
112
        }
 
113
      break;
 
114
    }
 
115
 
 
116
}
 
117
 
 
118
void C2F(fac3dn)(sciPointObj *pobj, double *x, double *y, double *z, integer *cvect, integer *p, integer *q)
 
119
{
 
120
  integer polysize,npoly,whiteid,verbose=0,narg,fg1;
 
121
  integer *polyx,*polyy,*locindex,fill[4]; 
 
122
  static double zmin,zmax,*polyz;
 
123
  integer i,flag,iflag; 
 
124
  sciPointObj *psubwin;
 
125
 
 
126
 
 
127
  psubwin = sciGetSelectedSubWin (sciGetCurrentFigure ()); 
 
128
 
 
129
  zmin  = pSUBWIN_FEATURE(psubwin)->SRect[4]; /*zmin*/
 
130
  zmax  = pSUBWIN_FEATURE(psubwin)->SRect[5]; /*zmax*/
 
131
 
 
132
  fg1        = pSURFACE_FEATURE (pobj)->hiddencolor; 
 
133
  flag       = pSURFACE_FEATURE (pobj)->flag[0];
 
134
  iflag      = pSURFACE_FEATURE (pobj)->flagcolor;
 
135
 
 
136
  polyz = graphic_alloc(5,(*q),sizeof(double));
 
137
  if ( (polyz == NULL) && (*q) != 0)
 
138
    {
 
139
      Scistring("plot3dg_ : malloc No more Place\n");
 
140
      return;
 
141
    }
 
142
  /** Allocation  **/
 
143
  polyx = graphic_alloc(0,(*p)+1L,sizeof(int));
 
144
  polyy = graphic_alloc(1,(*p)+1L,sizeof(int));
 
145
  locindex = graphic_alloc(2,(*q),sizeof(int));
 
146
  if ( ( polyx == NULL) ||  ( polyy== NULL) || ( locindex== NULL) )
 
147
    {
 
148
      Scistring("plot3dg_ : malloc No more Place\n");
 
149
      return;
 
150
    }
 
151
 
 
152
  /** le tri des facettes **/
 
153
  for ( i =0 ; i < *q ; i++)
 
154
    {
 
155
      double zdmin1, zdmin,xmoy=0.00,ymoy=0.00,zmoy=0.00;
 
156
      int j=0 ;
 
157
      zdmin1=  TRZ(x[ (*p)*i]  ,y[(*p)*i]  ,z[(*p)*i]);
 
158
      for ( j= 0 ; j < *p ; j++) 
 
159
        {
 
160
          xmoy += x[ j +(*p)*i];  ymoy += y[ j +(*p)*i];  zmoy += z[ j +(*p)*i];
 
161
          zdmin =  TRZ(x[ j +(*p)*i]  ,y[ j +(*p)*i]  ,z[ j +(*p)*i]);
 
162
          if ( zdmin1 < zdmin ) zdmin1= zdmin;
 
163
        }
 
164
         polyz[i]=  TRZ(xmoy,ymoy,zmoy);
 
165
    }
 
166
  C2F(dsort)(polyz,q,locindex); 
 
167
  for ( i =0 ; i < (*q) ; i++)
 
168
    {
 
169
      locindex[i] -= 1;  
 
170
      if ( locindex[i] >= *q) 
 
171
        sciprint (" index[%d]=%d\r\n",i,locindex[i]);
 
172
      locindex[i] = Min(Max(0,locindex[i]),*q-1);
 
173
    }
 
174
  polysize=(*p)+1;
 
175
  npoly=1; 
 
176
 
 
177
  C2F(dr)("xget","lastpattern",&verbose,&whiteid,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
178
  fill[0]=  flag; 
 
179
  /*if (fg1<=0) fg1= flag;*/
 
180
 
 
181
  for ( i = (*q)-1 ; i>= 0 ; i--)
 
182
    {
 
183
      int j,nok=0;
 
184
      for ( j =0 ; j < (*p) ; j++)
 
185
        { 
 
186
        if (trans3d(psubwin ,1, &(polyx[j]),&(polyy[j]),&(x[(*p)*locindex[i]+j]),
 
187
                &(y[(*p)*locindex[i]+j]),&(z[(*p)*locindex[i]+j]))==0)
 
188
            {
 
189
              nok=1;break; 
 
190
            }
 
191
        }
 
192
      if ( nok == 0) 
 
193
        {
 
194
          polyx[(*p)]=polyx[0];
 
195
          polyy[(*p)]=polyy[0];
 
196
          fill[0]=  flag;
 
197
           if (( *p >= 2 && ((polyx[1]-polyx[0])*(polyy[2]-polyy[0])-
 
198
                             (polyy[1]-polyy[0])*(polyx[2]-polyx[0])) <  0) && (fg1>=0))
 
199
            { 
 
200
              if (iflag != 0)
 
201
                fill[0] = (flag < 0 ) ? -fg1 : fg1 ;
 
202
              else
 
203
                fill[0] = (flag != 0 ) ? fg1 : flag ;
 
204
              /*if (flag==0) fill[0]=0;*/
 
205
               if (fill[0]>0) 
 
206
                {
 
207
                  C2F(dr)("xliness","str",polyx,polyy,fill,&npoly,&polysize,
 
208
                          PI0,PD0,PD0,PD0,PD0,0L,0L); 
 
209
                }
 
210
            }
 
211
          else if ( iflag == 1) 
 
212
            {
 
213
              double zl=0;
 
214
              int k;
 
215
              for ( k= 0 ; k < *p ; k++) zl+= z[(*p)*locindex[i]+k];
 
216
 
 
217
              fill[0]=inint((whiteid-1)*((zl/(*p))-zmin)/(zmax-zmin))+1;
 
218
              if ( flag < 0 ) fill[0]=-fill[0];
 
219
              C2F(dr)("xliness","str",polyx,polyy,fill,&npoly,&polysize ,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
220
            }
 
221
          else if ( iflag == 2) 
 
222
            {
 
223
              fill[0]= cvect[locindex[i]];
 
224
              if ( flag < 0 ) fill[0]=-fill[0];
 
225
              C2F(dr)("xliness","str",polyx,polyy,fill,&npoly,&polysize ,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
226
            }
 
227
          else if (iflag ==3) { 
 
228
              int k;
 
229
              ;
 
230
              if ( (*p) != 3 && (*p) !=4 ) {
 
231
                Scistring("plot3d1 : interpolated shading is only allowed for polygons with 3 or 4 vertices\n");
 
232
                return;
 
233
              } else {
 
234
                for ( k= 0 ; k < *p ; k++) fill[k]= cvect[(*p)*locindex[i]+k];
 
235
                 shade(polyx,polyy,fill,*p,flag);
 
236
              }
 
237
          }
 
238
          else C2F(dr)("xliness","str",polyx,polyy,fill,&npoly,&polysize ,PI0,PD0,PD0,PD0,PD0,0L,0L);
 
239
 
 
240
        }
 
241
    } 
 
242
}
 
243
 
 
244