drawGrayplotEntity.c File Reference

#include <string.h>
#include "drawGrayplotEntity.h"
#include "GetProperty.h"
#include "clipping.h"
#include "sciprint.h"
#include "Gray.h"
#include "BasicAlgos.h"
#include "axesScale.h"
#include "math_graphics.h"
#include "Xcall1.h"
#include "PloEch.h"
#include "MALLOC.h"
#include "periScreen.h"

Include dependency graph for drawGrayplotEntity.c:

Go to the source code of this file.

Functions

int drawGrayplotEntity (sciPointObj *pObj)


Function Documentation

int drawGrayplotEntity ( sciPointObj pObj  ) 

Routine which draw a grayplot object

Parameters:
pObj the pointer on the grayplot object

Boundaries of the frame

Boundaries of the frame

Definition at line 25 of file drawGrayplotEntity.c.

References sciSubWindow::axes, C2F, createDoubleArrayCopy(), sciGrayplot::datamapping, dr(), echelle2d(), frame_clip_off(), frame_clip_on(), FREE, GraySquare1(), GraySquare1_NGreverse(), GraySquareDirect(), GraySquareScaled(), i, inint, j, L, MALLOC, Maxi(), MaybeSetWinhdc(), Mini(), n1, n2, NULL, sciGrayplot::nx, sciGrayplot::ny, PD0, pGRAYPLOT_FEATURE, PI0, pSUBWIN_FEATURE, sciGrayplot::pvecx, sciGrayplot::pvecy, sciGrayplot::pvecz, ReleaseWinHdc(), AXES::reverse, ReverseDataFor3DXonly(), ReverseDataFor3DYonly(), sciGetIs3d(), sciGetParentSubwin(), sciGetVisibility(), sciprint(), SMDOUBLE, trans3d(), sciGrayplot::type, XScale(), YScale(), and z.

Referenced by sciDrawObj().

00026 {
00027   sciGrayplot * ppGray = pGRAYPLOT_FEATURE( pObj ) ;
00028   sciPointObj * parentSubWin = sciGetParentSubwin( pObj ) ;
00029   int n1 = ppGray->nx ;
00030   int n2 = ppGray->ny ;
00031 
00032   if ( !sciGetVisibility(pObj) ) { return 0 ; }
00033 
00034   switch ( ppGray->type )
00035   {
00036 
00037   case 0:  /* Grayplot case */
00038     if( !sciGetIs3d( parentSubWin ) )
00039     {
00040       int * xCoords = NULL ;
00041       int * yCoords = NULL ;
00042       int i ;
00043       int j ;
00044 
00045       /* F.Leray 19.05.05 : Now I use only xliness (not xfrect) */
00046       /* to better manage axes reversing */
00047 
00048       xCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00049       if ( xCoords == NULL )
00050       {
00051         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00052         return -1 ;
00053       }
00054 
00055       yCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00056       if ( yCoords == NULL )
00057       {
00058         FREE( xCoords ) ;
00059         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00060         return -1 ;
00061       }
00062 
00063       for ( i = 0 ; i < n1 ; i++ )  /* on x*/
00064       {
00065         for ( j = 0 ; j < n2 ; j++ )  /* on y */
00066         {
00067           xCoords[i+j*n1]= XScale(ppGray->pvecx[i]);
00068           yCoords[j+i*n2]= YScale(ppGray->pvecy[j]);
00069         }
00070       }
00071 
00072 #ifdef _MSC_VER
00073         flag_DO = MaybeSetWinhdc();
00074 #endif
00075         frame_clip_on();
00076 
00077         if ( strncmp( ppGray->datamapping,"scaled", 6) == 0 )
00078         {
00079           GraySquareScaled(xCoords,yCoords,ppGray->pvecz,n1,n2); /* SS 03/01/03 */
00080         }
00081         else
00082         {
00083           GraySquareDirect(xCoords,yCoords,ppGray->pvecz,n1,n2);
00084         }
00085 
00086         frame_clip_off();
00087 #ifdef _MSC_VER
00088         if ( flag_DO == 1) { ReleaseWinHdc() ; }
00089 #endif
00090 
00091         FREE(xCoords);
00092         FREE(yCoords);
00093 
00094     }
00095     else
00096     {
00097       /*3D version */
00098       double * xvect   = NULL;
00099       double * yvect   = NULL;
00100       int    * xCoords = NULL ;
00101       int    * yCoords = NULL ;
00102       int i ;
00103       int j ;
00104 
00105       xvect = createDoubleArrayCopy( ppGray->pvecx, n1 ) ;
00106       if ( xvect == NULL )
00107       {
00108         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00109         return -1 ;
00110       }
00111 
00112       yvect = createDoubleArrayCopy( ppGray->pvecy, n2 ) ;
00113       if ( yvect == NULL )
00114       {
00115         FREE(xvect) ;
00116         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00117         return -1 ;
00118       }
00119 
00120       xCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00121       if ( xCoords == NULL )
00122       {
00123         FREE(xvect) ;
00124         FREE(yvect) ;
00125         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00126         return -1 ;
00127       }
00128 
00129       yCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00130       if ( yCoords == NULL )
00131       {
00132         FREE(xvect) ;
00133         FREE(yvect) ;
00134         FREE(xCoords) ;
00135         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00136         return -1 ;
00137       }
00138 
00139       ReverseDataFor3DXonly(parentSubWin,xvect,n1);
00140       ReverseDataFor3DYonly(parentSubWin,yvect,n2);
00141 
00142       for ( i =0 ; i < n1 ; i++)  /* on x*/
00143       {
00144         for ( j =0 ; j < n2 ; j++)  /* on y */
00145         {
00146           trans3d(parentSubWin,1,&xCoords[i+j*n1],&yCoords[j+i*n2],
00147           &xvect[i],&yvect[j],NULL);
00148         }
00149       }
00150 
00151 #ifdef _MSC_VER
00152       flag_DO = MaybeSetWinhdc();
00153 #endif
00154       frame_clip_on(); 
00155 
00156       /* draw the filled projected rectangle */
00157 
00158       for (i = 0 ; i < (n1)-1 ; i++)
00159       {
00160         for (j = 0 ; j < (n2)-1 ; j++)
00161         {
00162           integer vertexx[5], vertexy[5];
00163           int five = 5 ;
00164           int one = 1;
00165           double zmoy,zmax,zmin,zmaxmin;
00166           integer verbose= 0 ;
00167           integer whiteid,fill[1],cpat,xz[2];
00168           double * z = ppGray->pvecz;
00169           int narg = 0 ;
00170           zmin = Mini(z,(n1)*(n2));
00171           zmax = Maxi(z,(n1)*(n2));
00172           zmaxmin = zmax - zmin ;
00173 
00174           if (zmaxmin <= SMDOUBLE) { zmaxmin = SMDOUBLE ; }
00175           C2F(dr)("xget","lastpattern",&verbose,&whiteid,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00176           C2F(dr)("xget","pattern",&verbose,&cpat,&narg,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00177           C2F(dr)("xget","wdim",&verbose,xz,&narg, PI0, PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
00178 
00179 
00180           if(strncmp(ppGray->datamapping,"scaled", 6) == 0)
00181           {
00182             /* color for current rectangle */
00183             zmoy=1/4.0*(z[i+n1*j]+z[i+n1*(j+1)]+z[i+1+n1*j]+z[i+1+n1*(j+1)]);
00184 
00185             fill[0]=1 + inint((whiteid-1)*(zmoy-zmin)/(zmaxmin));  
00186 
00187             fill[0] = - fill[0]; /* not to have contour with foreground color around the rectangle */
00188           }
00189           else /* "direct" mode is used */
00190           {
00191             fill[0] = - (int) z[j+n1*i];
00192           }
00193 
00194           vertexx[0] = xCoords[i+n1*j];
00195           vertexx[1] = xCoords[i+n1*(j+1)];
00196           vertexx[2] = xCoords[i+1+n1*(j+1)];
00197           vertexx[3] = xCoords[i+1+n1*j];
00198           vertexx[4] = xCoords[i+n1*j];
00199 
00200           vertexy[0] = yCoords[j+n2*i];
00201           vertexy[1] = yCoords[j+1+n2*i];
00202           vertexy[2] = yCoords[j+1+n2*(i+1)];
00203           vertexy[3] = yCoords[j+n2*(i+1)];
00204           vertexy[4] = yCoords[j+n2*i];
00205 
00206           C2F(dr)("xliness","str",vertexx,vertexy,fill,&one,&five,
00207             PI0,PD0,PD0,PD0,PD0,0L,0L);
00208         }
00209       }
00210 
00211       frame_clip_off();  
00212 #ifdef _MSC_VER
00213       if ( flag_DO == 1) ReleaseWinHdc();
00214 #endif
00215 
00216       FREE( xCoords ) ;
00217       FREE( yCoords ) ;
00218       FREE( xvect   )  ;
00219       FREE( yvect   )  ;
00220     }
00221     break;
00222   case 1: /* Matplot case */
00223     {
00224       /* In this case (and inside Matplot1 too but Matplot and Matplot1 are almost the same), */
00225       /* dim x = n2 and dim y = n1 (cf. scimatplot in matdes.c) */ /* F.Leray 20.05.05 */
00226       sciSubWindow * ppsubwin = pSUBWIN_FEATURE(parentSubWin) ;
00227 
00228       if( !sciGetIs3d(parentSubWin) )
00229       {
00230         int * xCoords = NULL ;
00231         int * yCoords = NULL ;
00232         int j ;
00233   
00234         xCoords = MALLOC( n2 * sizeof(int) ) ;
00235         if ( xCoords == NULL )
00236         {
00237           sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00238           return -1 ;
00239         }
00240 
00241         yCoords = MALLOC( n1 * sizeof(int) ) ;
00242         if ( yCoords == NULL )
00243         {
00244           FREE( xCoords ) ;
00245           sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00246           return -1 ;
00247         }
00248 
00249         for ( j =0 ; j < n2 ; j++) { xCoords[j] = XScale(j+0.5) ; }
00250         for ( j =0 ; j < n1 ; j++) { yCoords[j] = YScale(((n1-1)-j+0.5)) ; }
00251 #ifdef _MSC_VER
00252         flag_DO = MaybeSetWinhdc();
00253 #endif
00254         frame_clip_on(); 
00255         if( ppsubwin->axes.reverse[0] || ppsubwin->axes.reverse[1] )
00256         {
00257           GraySquare1_NGreverse(xCoords,yCoords,ppGray->pvecz,n1,n2,parentSubWin);
00258         }
00259         else
00260         {
00261           GraySquare1(xCoords,yCoords,ppGray->pvecz,n1,n2);  
00262         }
00263         frame_clip_off();
00264 #ifdef _MSC_VER
00265         if ( flag_DO == 1) { ReleaseWinHdc() ; }
00266 #endif
00267 
00268         FREE( xCoords );
00269         FREE( yCoords ) ;
00270       }
00271       else
00272       {
00273         /* 3D version */
00274         double * xvect   = NULL ;
00275         double * yvect   = NULL ;
00276         int    * xCoords = NULL ;
00277         int    * yCoords = NULL ;
00278         int i ;
00279         int j ;
00280 
00281         /* Warning here (Matplot case) : n1 becomes n2 and vice versa */
00282         xvect = MALLOC( n2 * sizeof(double) ) ;
00283         if ( xvect == NULL )
00284         {
00285           sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00286           return -1 ;
00287         }
00288 
00289         yvect = MALLOC( n1 * sizeof(double) ) ;
00290         if ( yvect == NULL )
00291         {
00292           FREE( xvect ) ;
00293           sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00294           return -1 ;
00295         }
00296 
00297         for ( i = 0 ; i < n2 ; i++ ) { xvect[i] = i + 0.5 ; }
00298         for ( i = 0 ; i < n1 ; i++ ) { yvect[i] = n1 - 1 - i + 0.5 ; }
00299 
00300         xCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00301         if ( xCoords == NULL )
00302         {
00303           FREE( xvect ) ;
00304           FREE( yvect ) ;
00305           sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00306           return -1 ;
00307         }
00308 
00309         yCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00310         if ( yCoords == NULL )
00311         {
00312           FREE( xvect ) ;
00313           FREE( yvect ) ;
00314           FREE( xCoords ) ;
00315           sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00316           return -1 ;
00317         }
00318 
00319         ReverseDataFor3DXonly(parentSubWin,xvect,n2);
00320         ReverseDataFor3DYonly(parentSubWin,yvect,n1);
00321 
00322 
00323         for ( i =0 ; i < n2 ; i++)  /* on x*/
00324         {
00325           for ( j =0 ; j < n1 ; j++)  /* on y */
00326           {
00327             trans3d(parentSubWin,1,&xCoords[i+j*n2],&yCoords[j+i*n1],&xvect[i],&yvect[j],NULL);
00328           }
00329         }
00330 #ifdef _MSC_VER
00331         flag_DO = MaybeSetWinhdc();
00332 #endif
00333         frame_clip_on(); 
00334 
00335         /* draw the filled projected rectangle */
00336         for (i = 0 ; i < (n2)-1 ; i++)
00337         {
00338           for (j = 0 ; j < (n1)-1 ; j++)
00339           {
00340             integer vertexx[5], vertexy[5];
00341             int five = 5, one = 1;
00342             integer fill;
00343 
00344             fill = (int ) - ppGray->pvecz[(n1-1)*i+j];
00345 
00346             vertexx[0] = xCoords[i+n2*j];
00347             vertexx[1] = xCoords[i+n2*(j+1)];
00348             vertexx[2] = xCoords[i+1+n2*(j+1)];
00349             vertexx[3] = xCoords[i+1+n2*j];
00350             vertexx[4] = xCoords[i+n2*j];
00351 
00352             vertexy[0] = yCoords[j+n1*i];
00353             vertexy[1] = yCoords[j+1+n1*i];
00354             vertexy[2] = yCoords[j+1+n1*(i+1)];
00355             vertexy[3] = yCoords[j+n1*(i+1)];
00356             vertexy[4] = yCoords[j+n1*i];
00357 
00358             C2F(dr)("xliness","str",vertexx,vertexy,&fill,&one,&five,
00359               PI0,PD0,PD0,PD0,PD0,0L,0L);
00360           }
00361         }
00362 
00363         frame_clip_off();  
00364 #ifdef _MSC_VER
00365         if ( flag_DO == 1) { ReleaseWinHdc() ; }
00366 #endif
00367 
00368         FREE( xCoords ) ;
00369         FREE( yCoords ) ;
00370         FREE( xvect   ) ;
00371         FREE( yvect   ) ;
00372       }
00373     }
00374     break;
00375   case 2: /* Matplot1 case */
00376     /* In this case (and inside Matplot too but Matplot and Matplot1 are almost the same), */
00377     /* dim x = n2 and dim y = n1 (cf. scimatplot in matdes.c) */ /* F.Leray 20.05.05 */
00378 
00379     if( !sciGetIs3d(parentSubWin ) )
00380     {
00381       int * xCoords = NULL ;
00382       int * yCoords = NULL ;
00383       double xx[2] ;
00384       double yy[2];   
00385       int px1[2] ;
00386       int py1[2] ;
00387       int pn1 = 1 ;
00388       int pn2 = 2 ;
00389       int j ;
00390 
00391       xCoords = MALLOC( n2 * sizeof(int) ) ;
00392       if ( xCoords == NULL )
00393       {
00394         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00395         return -1 ;
00396       }
00397 
00398       yCoords = MALLOC( n1 * sizeof(int) ) ;
00399       if ( yCoords == NULL )
00400       {
00401         FREE( xCoords ) ;
00402         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00403         return -1 ;
00404       }
00405 
00406       xx[0]=ppGray->pvecx[0];
00407       xx[1]=ppGray->pvecx[2];
00408       yy[0]=ppGray->pvecx[1];
00409       yy[1]=ppGray->pvecx[3];
00411       C2F(echelle2d)(xx,yy,px1,py1,&pn1,&pn2,"f2i",3L); 
00412       for ( j =0 ; j < n2 ; j++)
00413       {
00414         xCoords[j]= (int) (( px1[1]*j + px1[0]*((n2-1)-j) )/(n2-1));
00415       }
00416 
00417       for ( j =0 ; j < n1 ; j++)
00418       {
00419         yCoords[j]= (int) (( py1[0]*j + py1[1]*((n1-1)-j) )/ (n1-1));
00420       }
00421 
00422 #ifdef _MSC_VER
00423       flag_DO = MaybeSetWinhdc();
00424 #endif
00425 
00426       frame_clip_on(); 
00427       GraySquare1(xCoords,yCoords,ppGray->pvecz,n1,n2); 
00428       frame_clip_off();
00429 #ifdef _MSC_VER
00430       if ( flag_DO == 1 ) { ReleaseWinHdc() ; }
00431 #endif
00432       FREE(xCoords) ;
00433       FREE(yCoords) ;
00434     }
00435     else{
00436       /* 3D version */
00437       double * xvect   = NULL;
00438       double * yvect   = NULL;
00439       int    * xCoords = NULL ;
00440       int    * yCoords = NULL ;
00441       double xx[2] ;
00442       double yy[2] ;
00443       int  i ;
00444       int  j ;
00445 
00446       /* Warning here (Matplot case) : n1 becomes n2 and vice versa */
00447       xvect = MALLOC( n2 * sizeof(double) ) ;
00448       if ( xvect == NULL )
00449       {
00450         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00451         return -1 ;
00452       }
00453 
00454       yvect = MALLOC( n1 * sizeof(double) ) ;
00455       if ( yvect == NULL )
00456       {
00457         FREE( xvect ) ;
00458         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00459         return -1 ;
00460       }
00461 
00462       xCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00463       if ( xCoords == NULL )
00464       {
00465         FREE( xvect ) ;
00466         FREE( yvect ) ;
00467         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00468         return -1 ;
00469       }
00470 
00471       yCoords = MALLOC( n1 * n2 * sizeof(int) ) ;
00472       if ( yCoords == NULL )
00473       {
00474         FREE( xvect ) ;
00475         FREE( yvect ) ;
00476         FREE( xCoords ) ;
00477         sciprint( "Unable to allocate temporary vector, memory full.\n" ) ;
00478         return -1 ;
00479       }
00480 
00481       xx[0]=ppGray->pvecx[0];
00482       xx[1]=ppGray->pvecx[2];
00483       yy[0]=ppGray->pvecx[1];
00484       yy[1]=ppGray->pvecx[3];
00485 
00486 
00488       for ( i =0 ; i < n2 ; i++)
00489       {
00490         xvect[i]= (( xx[1]*i + xx[0]*((n2-1)-i) )/(n2-1));
00491       }
00492 
00493       for ( j = 0 ; j < n1 ; j++ )
00494       {
00495         yvect[j]= (( yy[0]*j + yy[1]*((n1-1)-j) )/ (n1-1)); 
00496       }
00497 
00498       ReverseDataFor3DXonly(parentSubWin,xvect,n2);
00499       ReverseDataFor3DYonly(parentSubWin,yvect,n1);
00500 
00501 
00502       for ( i =0 ; i < n2 ; i++)  /* on x*/
00503       {
00504         for ( j =0 ; j < n1 ; j++)  /* on y */
00505         {
00506           trans3d(parentSubWin,1,&xCoords[i+j*n2],&yCoords[j+i*n1],
00507           &xvect[i],&yvect[j],NULL);
00508         }
00509       }
00510 #ifdef _MSC_VER
00511       flag_DO = MaybeSetWinhdc();
00512 #endif
00513       frame_clip_on(); 
00514 
00515       /* draw the filled projected rectangle */
00516       for ( i = 0 ; i < (n2)-1 ; i++ )
00517       {
00518         for ( j = 0 ; j < (n1)-1 ; j++ )
00519         {
00520           integer vertexx[5], vertexy[5];
00521           int five = 5, one = 1;
00522           integer fill;
00523 
00524           fill = (int) - ppGray->pvecz[(n1-1)*i+j];
00525 
00526           vertexx[0] = xCoords[i+n2*j];
00527           vertexx[1] = xCoords[i+n2*(j+1)];
00528           vertexx[2] = xCoords[i+1+n2*(j+1)];
00529           vertexx[3] = xCoords[i+1+n2*j];
00530           vertexx[4] = xCoords[i+n2*j];
00531 
00532           vertexy[0] = yCoords[j+n1*i];
00533           vertexy[1] = yCoords[j+1+n1*i];
00534           vertexy[2] = yCoords[j+1+n1*(i+1)];
00535           vertexy[3] = yCoords[j+n1*(i+1)];
00536           vertexy[4] = yCoords[j+n1*i];
00537 
00538           C2F(dr)("xliness","str",vertexx,vertexy,&fill,&one,&five,
00539             PI0,PD0,PD0,PD0,PD0,0L,0L);
00540         }
00541       }
00542 
00543       frame_clip_off();  
00544 #ifdef _MSC_VER
00545       if ( flag_DO == 1 ) { ReleaseWinHdc() ; }
00546 #endif
00547       FREE( xCoords ) ;
00548       FREE( yCoords ) ;
00549       FREE( xvect   ) ;
00550       FREE( yvect   ) ;
00551     }
00552     break;
00553   default:
00554     break;
00555   }
00556 
00557   return 0 ;
00558 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Mar 4 15:47:29 2007 for Scilab [trunk] by  doxygen 1.5.1