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