Back to index

plt-scheme  4.2.1
plimage.c
Go to the documentation of this file.
00001 /* plimage() 
00002  *
00003  * Author: Alessandro Mirone, Nov 2001
00004  * Adapted: Joao Cardoso
00005  */
00006 
00007 #include "plplotP.h"
00008 
00009 /* Get better names, those are too criptic!
00010  * 
00011  * ZEROW2B: zero writing to buffer ?
00012  * ZEROW2D: zero writing to display ?
00013  * ONEW2B: set writing to buffer ?
00014  * ONEW2D: set writing to display ?
00015  */
00016 
00017 void
00018 NoBufferNoPixmap()
00019 {
00020   PLINT op = ZEROW2B; 
00021 
00022   plsc->plbuf_write = 0; /* TODO: store previous state */
00023   plP_esc(PLESC_EXPOSE, NULL);
00024   plP_esc(PLESC_IMAGEOPS, &op);
00025 }
00026 
00027 void
00028 RestoreWrite2BufferPixmap()
00029 {
00030   PLINT op = ONEW2B;
00031 
00032   plsc->plbuf_write = 1; /* TODO: revert from previous state */
00033   plP_esc(PLESC_IMAGEOPS, &op);
00034 }
00035 
00036 void
00037 disabledisplay()
00038 {
00039   PLINT op = ZEROW2D;
00040 
00041   plP_esc(PLESC_IMAGEOPS, &op);
00042 }
00043 
00044 void
00045 enabledisplay()
00046 {
00047   PLINT op = ONEW2D;
00048 
00049   plP_esc(PLESC_IMAGEOPS, &op);
00050   plP_esc(PLESC_EXPOSE, NULL); 
00051 }
00052 
00053 
00054 
00055 void
00056 plimageslow(short *x, short *y, unsigned short *data, PLINT nx, PLINT ny, 
00057            PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
00058            unsigned short zmin, unsigned short zmax)
00059 {
00060   PLINT ix, iy, i;
00061   PLFLT xf[4], yf[4];
00062   short xs[5], ys[5];
00063   int corners[4];
00064   unsigned short col;
00065 
00066   for (ix = 0; ix < nx ; ix++) {
00067     for (iy = 0; iy < ny ; iy++) {
00068 
00069       col = data[ix*ny+iy];
00070       /* only plot points within zmin/zmax range */
00071       if (col < zmin || col > zmax)
00072        continue;
00073 
00074       plcol1(col/(float)USHRT_MAX);
00075 
00076       if (plsc->plbuf_read == 1) {
00077        /* buffer read, is a replot to a slow device. */
00078 
00079        corners[0] = ix*(ny+1)+iy;       /* [ix][iy] */
00080        corners[1] = (ix+1)*(ny+1)+iy;   /* [ix+1][iy] */
00081        corners[2] = (ix+1)*(ny+1)+iy+1; /* [ix+1][iy+1] */
00082        corners[3] = ix*(ny+1)+iy+1;     /* [ix][iy+1] */
00083 
00084        for (i = 0; i < 4; i++) {
00085          xs[i] = x[corners[i]];
00086          ys[i] = y[corners[i]];
00087        }
00088        xs[4] = xs[0]; ys[4] = ys[0];
00089        plP_fill(xs, ys, 5);
00090 
00091       } else {
00092 
00093        xf[0] = xf[1] = ix;
00094        xf[2] = xf[3] = ix+1;
00095        yf[0] = yf[3] = iy;
00096        yf[1] = yf[2] = iy+1;
00097 
00098        for (i = 0; i < 4; i++) {
00099          xf[i] = xmin + xf[i]*dx;
00100          yf[i] = ymin + yf[i]*dy;
00101        }
00102        plfill(4, xf, yf);
00103       }
00104     }
00105   }
00106 }
00107 
00108 void
00109 grimage(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny)
00110 {
00111     plsc->dev_ix = x;
00112     plsc->dev_iy = y;
00113     plsc->dev_z = z;
00114     plsc->dev_nptsX = nx;
00115     plsc->dev_nptsY = ny;
00116 
00117     plP_esc(PLESC_IMAGE, NULL);
00118 }
00119 
00120 /*-------------------------------------------------------------------------*\
00121  * plimage
00122  *           (***** SUBJECT TO CHANGE ******)
00123  *
00124  * arguments are
00125  *   data: array containing image data
00126  *   nx: dimension of the array in the X axis.        
00127  *   ny: dimension of the  array in the Y axis 
00128  *   The array data is indexed like data[ix][iy]
00129  *
00130  *   xmin, xmax, ymin, ymax:
00131  *       data[0][0] corresponds to (xmin,ymin)
00132  *       data[nx-1][ny-1] to (xmax,ymax)
00133  *
00134  *   zmin, zmax:
00135  *       only data within bounds zmin <= data <= zmax will be
00136  *       plotted. If zmin == zmax, all data will be ploted.
00137  *
00138  *   Dxmin, Dxmax, Dymin, Dymax:
00139  *       plots only the window of points whose(x,y)'s fall
00140  *       inside the [Dxmin->Dxmax]X[Dymin->Dymax] window
00141  *
00142 \*-------------------------------------------------------------------------*/
00143 
00144 void
00145 plimage(PLFLT **idata, PLINT nx, PLINT ny, 
00146        PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
00147        PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax)
00148 {
00149   PLINT nnx, nny, ix, iy, ixx, iyy, xm, ym;
00150   PLFLT dx, dy;
00151   unsigned short *Zf, szmin, szmax;
00152   short *Xf, *Yf;
00153   PLFLT lzmin, lzmax, tz;
00154   
00155   if (plsc->level < 3) {
00156     plabort("plimage: window must be set up first");
00157     return;
00158   }
00159 
00160   if (nx <= 0 || ny <= 0) {
00161     plabort("plimage: nx and ny must be positive");
00162     return;
00163   }
00164 
00165   if (Dxmin < xmin || Dxmax > xmax || Dymin < ymin || Dymax > ymax){
00166     plabort("plimage: Dxmin or Dxmax or Dymin or Dymax not compatible with xminor xmax or ymin or ymax.");
00167     return;
00168   }
00169 
00170   dx = (xmax - xmin) / (nx - 1);
00171   dy = (ymax - ymin) / (ny - 1);
00172   nnx = (Dxmax-Dxmin)/dx + 1;
00173   nny = (Dymax-Dymin)/dy + 1;
00174 
00175   Zf = (unsigned short *) malloc(nny*nnx*sizeof(unsigned short));
00176 
00177   xm = floor((Dxmin-xmin)/dx); ym = floor((Dymin-ymin)/dy);
00178   lzmin = lzmax = idata[xm][ym];
00179   
00180   for (ix=xm; ix<xm+nnx; ix++) {
00181     for (iy=ym; iy<ym+nny; iy++) {
00182       tz = idata[ix][iy];
00183       if (lzmax < tz)
00184        lzmax = tz;
00185       if (lzmin > tz)
00186        lzmin = tz;
00187     }
00188   }
00189 
00190   ixx=-1;
00191   for (ix=xm; ix<xm+nnx; ix++) {
00192     ixx++; iyy=0;
00193     for (iy=ym; iy<ym+nny; iy++)
00194       Zf[ixx*nny+iyy++] = (idata[ix][iy] - lzmin)/(lzmax-lzmin)*USHRT_MAX;
00195   }
00196 
00197   if (zmin == zmax) {
00198     zmin = lzmin;
00199     zmax = lzmax;
00200   } else {
00201     if (zmin < lzmin)
00202       zmin = lzmin;
00203 
00204     if (zmax > lzmax)
00205       zmax = lzmax;
00206   }
00207 
00208   szmin = (zmin - lzmin)/(lzmax-lzmin)*USHRT_MAX;
00209   szmax = (zmax - lzmin)/(lzmax-lzmin)*USHRT_MAX;
00210 
00211   xmin = Dxmin;  xmax = Dxmax;
00212   ymin = Dymin;  ymax = Dymax;
00213 
00214   /* The X and Y arrays has size nnx*nny */
00215   nnx++; nny++;
00216 
00217   Xf = (short *) malloc(nny*nnx*sizeof(short));
00218   Yf = (short *) malloc(nny*nnx*sizeof(short));
00219 
00220   /* adjust the step for the X/Y arrays */
00221   dx = dx*(nx-1)/nx;
00222   dy = dy*(ny-1)/ny;
00223 
00224   for (ix = 0; ix < nnx; ix++)
00225     for (iy = 0; iy < nny; iy++) {      
00226       Xf[ix*nny+iy] =  plP_wcpcx(xmin + ix*dx);
00227       Yf[ix*nny+iy] =  plP_wcpcy(ymin + iy*dy);
00228     }
00229 
00230   plP_image(Xf, Yf, Zf, nnx, nny, xmin, ymin, dx, dy, szmin, szmax);
00231 
00232   free(Xf);
00233   free(Yf);
00234   free(Zf);
00235 }