00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "plplotP.h"
00027
00028 #define COLOR_MIN 0.0
00029 #define COLOR_MAX 1.0
00030 #define COLOR_NO_PLOT (-1.0)
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 void
00041 NoBufferNoPixmap()
00042 {
00043 PLINT op = ZEROW2B;
00044
00045 plsc->plbuf_write = 0;
00046 plP_esc(PLESC_EXPOSE, NULL);
00047 plP_esc(PLESC_IMAGEOPS, &op);
00048 }
00049
00050 void
00051 RestoreWrite2BufferPixmap()
00052 {
00053 PLINT op = ONEW2B;
00054
00055 plsc->plbuf_write = 1;
00056 plP_esc(PLESC_IMAGEOPS, &op);
00057 }
00058
00059 void
00060 disabledisplay()
00061 {
00062 PLINT op = ZEROW2D;
00063
00064 plP_esc(PLESC_IMAGEOPS, &op);
00065 }
00066
00067 void
00068 enabledisplay()
00069 {
00070 PLINT op = ONEW2D;
00071
00072 plP_esc(PLESC_IMAGEOPS, &op);
00073 plP_esc(PLESC_EXPOSE, NULL);
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 void
00088 plimageslow(PLFLT *idata, PLINT nx, PLINT ny,
00089 PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
00090 void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
00091 PLPointer pltr_data)
00092 {
00093
00094 PLINT ix, iy, i;
00095
00096 PLFLT xf[4], yf[4];
00097
00098 PLFLT tx, ty;
00099
00100
00101
00102 PLFLT color;
00103
00104 plP_esc(PLESC_START_RASTERIZE, NULL);
00105 for (ix = 0; ix < nx ; ix++) {
00106 for (iy = 0; iy < ny ; iy++) {
00107
00108 color = idata[ix * ny + iy];
00109 if (color == COLOR_NO_PLOT)
00110 continue;
00111
00112
00113 plcol1(color / COLOR_MAX);
00114
00115 xf[0] = xf[1] = ix;
00116 xf[2] = xf[3] = ix + 1;
00117 yf[0] = yf[3] = iy;
00118 yf[1] = yf[2] = iy + 1;
00119
00120 if (pltr) {
00121 for (i = 0; i < 4; i++) {
00122
00123 (*pltr) (xf[i], yf[i], &tx, &ty, pltr_data);
00124 xf[i] = tx;
00125 yf[i] = ty;
00126 }
00127 }
00128 else {
00129 for (i = 0; i < 4; i++) {
00130
00131 xf[i] = xmin + xf[i] * dx;
00132 yf[i] = ymin + yf[i] * dy;
00133 }
00134 }
00135 plfill(4, xf, yf);
00136 }
00137 }
00138 plP_esc(PLESC_END_RASTERIZE, NULL);
00139 }
00140
00141 void
00142 grimage(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny)
00143 {
00144 plsc->dev_ix = x;
00145 plsc->dev_iy = y;
00146 plsc->dev_z = z;
00147 plsc->dev_nptsX = nx;
00148 plsc->dev_nptsY = ny;
00149
00150 plP_esc(PLESC_IMAGE, NULL);
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 void
00185 c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
00186 PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
00187 PLFLT valuemin, PLFLT valuemax,
00188 void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
00189 PLPointer pltr_data)
00190 {
00191 PLINT ix, iy;
00192 PLFLT dx, dy;
00193
00194 PLFLT *z;
00195
00196
00197 PLFLT datum;
00198
00199 PLINT init_color;
00200
00201 if (plsc->level < 3) {
00202 plabort("plimagefr: window must be set up first");
00203 return;
00204 }
00205
00206 if (nx <= 0 || ny <= 0) {
00207 plabort("plimagefr: nx and ny must be positive");
00208 return;
00209 }
00210
00211 if ((z = (PLFLT *) malloc(ny * nx * sizeof(PLFLT))) == NULL) {
00212 plexit("plimagefr: Insufficient memory");
00213 }
00214
00215
00216 init_color = plsc->icol0;
00217
00218
00219
00220 if (zmin == zmax) {
00221
00222 plMinMax2dGrid(idata, nx, ny, &zmax, &zmin);
00223 }
00224
00225
00226
00227
00228
00229
00230
00231 for (ix = 0; ix < nx; ix++) {
00232 for (iy = 0; iy < ny; iy++) {
00233 if (valuemin == valuemax) {
00234
00235 z[ix * ny + iy] = (COLOR_MAX + COLOR_MIN) / 2.0;
00236 }
00237 else {
00238 datum = idata[ix][iy];
00239 if (isnan(datum) || datum < zmin || datum > zmax) {
00240
00241 z[ix * ny + iy] = COLOR_NO_PLOT;
00242 }
00243 else {
00244 if (datum < valuemin) {
00245 datum = valuemin;
00246 }
00247 else if (datum > valuemax) {
00248 datum = valuemax;
00249 }
00250
00251 z[ix * ny + iy] =
00252 (datum - valuemin + COLOR_MIN) / (valuemax - valuemin) * COLOR_MAX;
00253 }
00254 }
00255 }
00256 }
00257
00258
00259
00260 dx = (xmax - xmin) / (PLFLT)nx;
00261 dy = (ymax - ymin) / (PLFLT)ny;
00262
00263 plP_image(z, nx, ny, xmin, ymin, dx, dy, pltr, pltr_data);
00264
00265 plcol0(init_color);
00266
00267 free(z);
00268 }
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 void
00293 c_plimage(PLFLT **idata, PLINT nx, PLINT ny,
00294 PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
00295 PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax)
00296 {
00297 PLINT ix, iy, ixx, iyy, xm, ym, nnx, nny;
00298 PLFLT data_min, data_max, dx, dy;
00299
00300 PLFLT **z;
00301
00302 PLBOOL copied;
00303 copied = FALSE;
00304
00305 if (nx <= 0 || ny <= 0) {
00306 plabort("plimage: nx and ny must be positive");
00307 return;
00308 }
00309
00310 if (Dxmin < xmin || Dxmax > xmax || Dymin < ymin || Dymax > ymax) {
00311 plabort("plimage: Dxmin or Dxmax or Dymin or Dymax not compatible with xmin or xmax or ymin or ymax.");
00312 return;
00313 }
00314
00315 if (Dxmax < Dxmin || xmax < xmin || Dymax < Dymin || ymax < ymin) {
00316 plabort("plimage: All (Dxmin < Dxmax) and (Dymin < Dymax) and (xmin < xmax) and (ymin < ymax) must hold.");
00317 return;
00318 }
00319
00320
00321
00322 plMinMax2dGrid(idata, nx, ny, &data_max, &data_min);
00323
00324 if (xmin == Dxmin && xmax == Dxmax && ymin == Dymin && ymax == Dymax) {
00325
00326 z = idata;
00327 nnx = nx;
00328 nny = ny;
00329 }
00330 else {
00331
00332
00333 dx = (xmax - xmin) / (PLFLT)nx;
00334 dy = (ymax - ymin) / (PLFLT)ny;
00335
00336
00337 nnx = (PLINT)ceil((Dxmax - Dxmin) / dx);
00338 nny = (PLINT)ceil((Dymax - Dymin) / dy);
00339
00340
00341
00342
00343 xm = (PLINT)floor((Dxmin - xmin) / dx);
00344 ym = (PLINT)floor((Dymin - ymin) / dy);
00345
00346
00347 plAlloc2dGrid(&z, nnx, nny);
00348
00349
00350
00351 ixx = -1;
00352 for (ix = xm; ix < xm + nnx; ix++) {
00353 ixx++; iyy=0;
00354 for (iy = ym; iy < ym + nny; iy++) {
00355 z[ixx][iyy++] = idata[ix][iy];
00356 }
00357 }
00358
00359
00360 copied = TRUE;
00361 }
00362
00363 plimagefr(z, nnx, nny, Dxmin, Dxmax, Dymin, Dymax, zmin, zmax,
00364 data_min, data_max, NULL, NULL);
00365
00366
00367 if (copied == TRUE) {
00368 plFree2dGrid(z, nnx, nny);
00369 }
00370 }