Cut up scidrawobj routine. One routine was created for each kind of handle.
[scilab.git] / scilab / modules / graphics / src / c / axesScale.c
1 /*------------------------------------------------------------------------*/
2 /* file: axesScale.c                                                      */
3 /* Copyright INRIA 2006                                                   */
4 /* Authors : Fabrice Leray, Jean-Baptiste Silvy                           */
5 /* desc : Contains functions to compute scale changes in a specific       */
6 /*        subwindow.                                                      */
7 /*------------------------------------------------------------------------*/
8
9
10 #include "axesScale.h"
11 #include "math_graphics.h"
12 #include "MALLOC.h"
13 #include "GetProperty.h"
14 #include "sciprint.h"
15 #include "PloEch.h"
16 #include "GraphicZoom.h"
17 #include "Vertices.h"
18
19 /*---------------------------------------------------------------------------------------*/
20 double InvAxis( double min, double max, double u )
21 {
22   /*return (u-min) / (max-min) * min + (u-max) / (min-max) * max ;*/
23   return min + max - u ; /* ahah little simplification */
24 }
25 /*---------------------------------------------------------------------------------------*/
26 int ReverseDataFor3DXonly( sciPointObj * psubwin, double xvect[], int n1 )
27 {
28   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin) ;
29   int cmp;
30
31   if( ppsubwin->axes.reverse[0] )
32   {
33     /* agir sur x */
34     if( ppsubwin->logflags[0] == 'l' )
35     {
36       for( cmp = 0 ; cmp < n1 ; cmp++ )
37       {
38         xvect[cmp] = log10( xvect[cmp] ) ;
39         xvect[cmp] = InvAxis( ppsubwin->FRect[0], ppsubwin->FRect[2], xvect[cmp] ) ;
40         xvect[cmp] = exp10( xvect[cmp] ) ;
41       }
42     }
43     else
44     {
45       for( cmp = 0 ; cmp < n1 ; cmp++ )
46       {
47         xvect[cmp] = InvAxis( ppsubwin->FRect[0], ppsubwin->FRect[2], xvect[cmp] ) ;
48       }
49     }
50   }
51
52   return 0 ;
53 }
54 /*---------------------------------------------------------------------------------------*/
55 int ReverseDataFor3DYonly( sciPointObj * psubwin, double yvect[], int n1 )
56 {
57   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
58   int cmp;
59
60   if( ppsubwin->axes.reverse[1] )
61   {
62     /* agir sur y */
63     if(ppsubwin->logflags[1]=='l'){
64       for(cmp=0;cmp<n1;cmp++)
65       {
66         yvect[cmp] = log10(yvect[cmp]);
67         yvect[cmp] = InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],yvect[cmp]);
68         yvect[cmp] = exp10(yvect[cmp]);
69       }
70     }
71     else
72     {
73       for(cmp=0;cmp<n1;cmp++)
74       {
75         yvect[cmp] =  InvAxis(ppsubwin->FRect[1],ppsubwin->FRect[3],yvect[cmp]);
76       }
77     }
78   }
79
80   return 0;
81 }
82 /*---------------------------------------------------------------------------------------*/
83 int ReverseDataFor3DZonly( sciPointObj * psubwin, double zvect[], int n1 )
84 {
85   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(psubwin);
86   int cmp;
87
88   if( zvect == NULL ) { return 0 ; }
89
90   if( ppsubwin->axes.reverse[2] )
91   {
92     /* agir sur z */
93     if(ppsubwin->logflags[2]=='l')
94     {
95       for(cmp=0;cmp<n1;cmp++)
96       {
97         zvect[cmp] = log10(zvect[cmp]);
98         zvect[cmp] = InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],zvect[cmp]);
99         zvect[cmp] = exp10(zvect[cmp]);
100       }
101     }
102     else
103     {
104       for(cmp=0;cmp<n1;cmp++)
105       {
106         zvect[cmp] =  InvAxis(ppsubwin->FRect[4],ppsubwin->FRect[5],zvect[cmp]);
107       }
108     }
109   }
110
111   return 0;
112 }
113 /*---------------------------------------------------------------------------------------*/
114 int ReverseDataFor3D( sciPointObj * psubwin, double xvect[], double yvect[], double zvect[], int n1 )
115 {
116
117   ReverseDataFor3DXonly(psubwin, xvect, n1);
118   ReverseDataFor3DYonly(psubwin, yvect, n1);
119   ReverseDataFor3DZonly(psubwin, zvect, n1);
120
121   return 0;
122 }
123 /*---------------------------------------------------------------------------------------*/
124 int trans3d( sciPointObj * pobj,
125              integer       n   ,
126              integer       xm[],
127              integer       ym[],
128              double        x[] ,
129              double        y[] ,
130              double        z[]  )
131 {
132   integer i;
133   double tmpx,tmpy,tmpz;
134   double  tmpx1,tmpy1,tmpz1;
135   /* TEST F.Leray 20.04.04: I fix HERE temporarily BOOL cube_scaling = FALSE; */
136   BOOL cube_scaling;
137   /* Test to enable reverse axis in 3D */ /* F.Leray 14.10.04 */
138   sciSubWindow * ppsubwin = pSUBWIN_FEATURE(pobj);
139
140   double *xtmp = NULL;
141   double *ytmp = NULL;
142   double xz1 ;
143   double yz1 ;
144
145   if (sciGetEntityType(pobj) != SCI_SUBWIN) { return 1 ; }
146
147   xtmp = MALLOC(n*sizeof(double));
148   ytmp = MALLOC(n*sizeof(double));
149
150   cube_scaling = pSUBWIN_FEATURE(pobj)->cube_scaling;
151
152   if( !cube_scaling)
153   {
154     if (z == (double *) NULL)
155     {
156       for ( i=0 ; i < n ; i++)
157       {
158         /* F.Leray 19.10.04 */
159         /* Test to export logscale in 3D */
160
161         if(ppsubwin->logflags[0] == 'l')
162         {
163           tmpx = log10(x[i]);
164         }
165         else
166         {
167           tmpx = x[i];
168         }
169
170         if(ppsubwin->logflags[1] == 'l')
171         {
172           tmpy = log10(y[i]);
173         }
174         else
175         {
176           tmpy = y[i];
177         }
178
179         if(ppsubwin->logflags[2] == 'l'){
180           sciprint("Warning: Value on z data is negative or zero while logarithmic scale enabled\n");
181           sciprint("Object not drawn\n");
182           FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
183           return 0;
184         }
185
186         xz1 = TX3D(tmpx,tmpy,0.0);
187         yz1 = TY3D(tmpx,tmpy,0.0);
188         xm[i] = inint( xz1 ) ;
189         ym[i] = inint( yz1 ) ;
190
191         if( isZoom3dOn() )
192         {
193           Store3DPixelValues(pobj,xm[i],ym[i],tmpx,tmpy,0.); /* stockage des xm, ym pour le zoom */
194         }
195
196         if ( finite(xz1)==0||finite(yz1)==0 ){
197           FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
198           return(0);
199         }
200       }
201     }
202     else /* z != NULL */
203     {
204       for ( i=0 ; i < n ; i++) /* cas 3d le + general */
205       {
206
207         /* F.Leray 19.10.04 */
208         /* Test to export logscale in 3D */
209
210         if(ppsubwin->logflags[0] == 'l')
211           tmpx = log10(x[i]);
212         else
213           tmpx = x[i];
214
215         if(ppsubwin->logflags[1] == 'l')
216           tmpy = log10(y[i]);
217         else
218           tmpy = y[i];
219
220         if(ppsubwin->logflags[2] == 'l')
221           tmpz = log10(z[i]);
222         else
223           tmpz = z[i];
224
225         
226         xz1 = TX3D(tmpx,tmpy,tmpz);
227         yz1 = TY3D(tmpx,tmpy,tmpz);
228         xm[i] = inint( xz1 ) ;
229         ym[i] = inint( yz1 ) ;
230
231         if( isZoom3dOn() )
232           Store3DPixelValues(pobj,xm[i],ym[i],tmpx,tmpy,tmpz); /* stockage des xm, ym pour le zoom */
233
234         if ( finite(xz1)==0||finite(yz1)==0 ){
235           FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
236           return(0);
237         }
238         /*      } */
239       }
240       FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
241     }
242   }
243   else   /* cube_scaling == TRUE now */
244   {
245     if (z == (double *) NULL)
246     {
247       for ( i=0 ; i < n ; i++)
248       {
249
250         /* F.Leray 03.11.04 */
251         /* Test to export logscale in 3D */
252
253         if(ppsubwin->logflags[0] == 'l')
254           tmpx = log10(x[i]);
255         else
256           tmpx = x[i];
257
258         if(ppsubwin->logflags[1] == 'l')
259           tmpy = log10(y[i]);
260         else
261           tmpy = y[i];
262
263         if(ppsubwin->logflags[2] == 'l'){
264           sciprint("Warning: Value on z data is negative or zero while logarithmic scale enabled\n");
265           sciprint("Object not drawn\n");
266           FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
267           return 0;
268         }
269
270         tmpx1 = tmpx;
271         tmpy1 = tmpy;
272         tmpz1 = 0.;
273
274         tmpx=(tmpx-pSUBWIN_FEATURE (pobj)->FRect[0])/(pSUBWIN_FEATURE (pobj)->FRect[2]-pSUBWIN_FEATURE (pobj)->FRect[0]);
275         tmpy=(tmpy-pSUBWIN_FEATURE (pobj)->FRect[1])/(pSUBWIN_FEATURE (pobj)->FRect[3]-pSUBWIN_FEATURE (pobj)->FRect[1]);
276         tmpz=(0.-pSUBWIN_FEATURE (pobj)->FRect[4])/(pSUBWIN_FEATURE (pobj)->FRect[5]-pSUBWIN_FEATURE (pobj)->FRect[4]); /* Adding F.Leray 04.11.04 */
277
278         xz1 = TX3D(tmpx,tmpy,tmpz);
279         yz1 = TY3D(tmpx,tmpy,tmpz);
280         xm[i] = inint( xz1 ) ;
281         ym[i] = inint( yz1 ) ;
282
283         if( isZoom3dOn())
284           Store3DPixelValues(pobj,xm[i],ym[i],tmpx1,tmpy1,tmpz1); /* stockage des xm, ym pour le zoom */
285
286         if ( finite(xz1)==0||finite(yz1)==0 ){
287           FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
288           return(0);
289         }
290       }
291     }
292     else /* z != NULL */
293     {
294       for ( i=0 ; i < n ; i++)
295       {
296
297         /* F.Leray 03.11.04 */
298         /* Test to export logscale in 3D */
299
300         if(ppsubwin->logflags[0] == 'l')
301           tmpx = log10(x[i]);
302         else
303           tmpx = x[i];
304
305         if(ppsubwin->logflags[1] == 'l')
306           tmpy = log10(y[i]);
307         else
308           tmpy = y[i];
309
310         if(ppsubwin->logflags[2] == 'l')
311           tmpz = log10(z[i]);
312         else
313           tmpz = z[i];
314
315         tmpx1 = tmpx;
316         tmpy1 = tmpy;
317         tmpz1 = tmpz;
318
319         tmpx= (tmpx-pSUBWIN_FEATURE (pobj)->FRect[0])/(pSUBWIN_FEATURE (pobj)->FRect[2]-pSUBWIN_FEATURE (pobj)->FRect[0]);
320         tmpy= (tmpy-pSUBWIN_FEATURE (pobj)->FRect[1])/(pSUBWIN_FEATURE (pobj)->FRect[3]-pSUBWIN_FEATURE (pobj)->FRect[1]);
321         tmpz= (tmpz-pSUBWIN_FEATURE (pobj)->FRect[4])/(pSUBWIN_FEATURE (pobj)->FRect[5]-pSUBWIN_FEATURE (pobj)->FRect[4]); /* Adding F.Leray 28.04.04 */
322
323         xz1 = TX3D(tmpx,tmpy,tmpz);
324         yz1 = TY3D(tmpx,tmpy,tmpz);
325         xm[i] = inint( xz1 ) ;
326         ym[i] = inint( yz1 ) ;
327
328         if( isZoom3dOn() )
329           Store3DPixelValues(pobj,xm[i],ym[i],tmpx1,tmpy1,tmpz1); /* stockage des xm, ym pour le zoom */
330
331         if ( finite(xz1)==0||finite(yz1)==0 ){
332           FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
333           return(0);
334         }
335       }
336     }
337   }
338   FREE(xtmp); xtmp = NULL; FREE(ytmp); ytmp = NULL;
339   return(1);
340 }
341 /*---------------------------------------------------------------------------------------*/