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 {
00107 for ( iy = 0; iy < ny; iy++ )
00108 {
00109
00110 color = idata[ix * ny + iy];
00111 if ( color == COLOR_NO_PLOT )
00112 continue;
00113
00114
00115 plcol1( color / COLOR_MAX );
00116
00117 xf[0] = xf[1] = ix;
00118 xf[2] = xf[3] = ix + 1;
00119 yf[0] = yf[3] = iy;
00120 yf[1] = yf[2] = iy + 1;
00121
00122 if ( pltr )
00123 {
00124 for ( i = 0; i < 4; i++ )
00125 {
00126
00127 ( *pltr )( xf[i], yf[i], &tx, &ty, pltr_data );
00128 xf[i] = tx;
00129 yf[i] = ty;
00130 }
00131 }
00132 else
00133 {
00134 for ( i = 0; i < 4; i++ )
00135 {
00136
00137 xf[i] = xmin + xf[i] * dx;
00138 yf[i] = ymin + yf[i] * dy;
00139 }
00140 }
00141 plfill( 4, xf, yf );
00142 }
00143 }
00144 plP_esc( PLESC_END_RASTERIZE, NULL );
00145 }
00146
00147 void
00148 grimage( short *x, short *y, unsigned short *z, PLINT nx, PLINT ny )
00149 {
00150 plsc->dev_ix = x;
00151 plsc->dev_iy = y;
00152 plsc->dev_z = z;
00153 plsc->dev_nptsX = nx;
00154 plsc->dev_nptsY = ny;
00155
00156 plP_esc( PLESC_IMAGE, NULL );
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
00185
00186
00187
00188
00189
00190 void
00191 c_plimagefr( const PLFLT **idata, PLINT nx, PLINT ny,
00192 PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
00193 PLFLT valuemin, PLFLT valuemax,
00194 void ( *pltr )( PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer ),
00195 PLPointer pltr_data )
00196 {
00197 plfimagefr( plf2ops_c(), (PLPointer) idata, nx, ny,
00198 xmin, xmax, ymin, ymax, zmin, zmax,
00199 valuemin, valuemax, pltr, pltr_data );
00200 }
00201
00202 void
00203 plfimagefr( PLF2OPS idataops, PLPointer idatap, PLINT nx, PLINT ny,
00204 PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
00205 PLFLT valuemin, PLFLT valuemax,
00206 void ( *pltr )( PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer ),
00207 PLPointer pltr_data )
00208 {
00209 PLINT ix, iy;
00210 PLFLT dx, dy;
00211
00212 PLFLT *z;
00213
00214
00215 PLFLT datum;
00216
00217 PLINT init_color;
00218
00219 PLFLT color_min, color_max, color_range;
00220
00221 if ( plsc->level < 3 )
00222 {
00223 plabort( "plimagefr: window must be set up first" );
00224 return;
00225 }
00226
00227 if ( nx <= 0 || ny <= 0 )
00228 {
00229 plabort( "plimagefr: nx and ny must be positive" );
00230 return;
00231 }
00232
00233 if ( ( z = (PLFLT *) malloc( ny * nx * sizeof ( PLFLT ) ) ) == NULL )
00234 {
00235 plexit( "plimagefr: Insufficient memory" );
00236 }
00237
00238
00239 init_color = plsc->icol0;
00240
00241
00242
00243 if ( zmin == zmax )
00244 {
00245
00246 idataops->minmax( idatap, nx, ny, &zmin, &zmax );
00247 }
00248
00249
00250 color_min = plsc->cmap1_min;
00251 color_max = plsc->cmap1_max;
00252 color_range = color_max - color_min;
00253
00254
00255
00256
00257
00258
00259
00260 for ( ix = 0; ix < nx; ix++ )
00261 {
00262 for ( iy = 0; iy < ny; iy++ )
00263 {
00264 if ( valuemin == valuemax )
00265 {
00266
00267 z[ix * ny + iy] = ( color_max + color_min ) / 2.0;
00268 }
00269 else
00270 {
00271 datum = idataops->get( idatap, ix, iy );
00272 if ( isnan( datum ) || datum < zmin || datum > zmax )
00273 {
00274
00275 z[ix * ny + iy] = COLOR_NO_PLOT;
00276 }
00277 else
00278 {
00279 if ( datum < valuemin )
00280 {
00281 datum = valuemin;
00282 }
00283 else if ( datum > valuemax )
00284 {
00285 datum = valuemax;
00286 }
00287
00288 z[ix * ny + iy] =
00289 color_min + ( datum - valuemin + COLOR_MIN ) / ( valuemax - valuemin ) * COLOR_MAX * color_range;
00290 }
00291 }
00292 }
00293 }
00294
00295
00296
00297 dx = ( xmax - xmin ) / (PLFLT) nx;
00298 dy = ( ymax - ymin ) / (PLFLT) ny;
00299
00300 plP_image( z, nx, ny, xmin, ymin, dx, dy, pltr, pltr_data );
00301
00302 plcol0( init_color );
00303
00304 free( z );
00305 }
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329 void
00330 c_plimage( const PLFLT **idata, PLINT nx, PLINT ny,
00331 PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
00332 PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax )
00333 {
00334 plfimage( plf2ops_c(), (PLPointer) idata, nx, ny,
00335 xmin, xmax, ymin, ymax, zmin, zmax,
00336 Dxmin, Dxmax, Dymin, Dymax );
00337 }
00338
00339 void
00340 plfimage( PLF2OPS idataops, PLPointer idatap, PLINT nx, PLINT ny,
00341 PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
00342 PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax )
00343 {
00344 PLINT ix, iy, ixx, iyy, xm, ym, nnx, nny;
00345 PLFLT data_min, data_max, dx, dy;
00346
00347 PLFLT **z;
00348 PLF2OPS zops;
00349
00350 PLBOOL copied;
00351 copied = FALSE;
00352
00353 if ( nx <= 0 || ny <= 0 )
00354 {
00355 plabort( "plimage: nx and ny must be positive" );
00356 return;
00357 }
00358
00359 if ( Dxmin < xmin || Dxmax > xmax || Dymin < ymin || Dymax > ymax )
00360 {
00361 plabort( "plimage: Dxmin or Dxmax or Dymin or Dymax not compatible with xmin or xmax or ymin or ymax." );
00362 return;
00363 }
00364
00365 if ( Dxmax < Dxmin || xmax < xmin || Dymax < Dymin || ymax < ymin )
00366 {
00367 plabort( "plimage: All (Dxmin < Dxmax) and (Dymin < Dymax) and (xmin < xmax) and (ymin < ymax) must hold." );
00368 return;
00369 }
00370
00371
00372
00373 idataops->minmax( idatap, nx, ny, &data_min, &data_max );
00374
00375 if ( xmin == Dxmin && xmax == Dxmax && ymin == Dymin && ymax == Dymax )
00376 {
00377
00378 z = (PLFLT **) idatap;
00379 zops = idataops;
00380 nnx = nx;
00381 nny = ny;
00382 }
00383 else
00384 {
00385
00386
00387 dx = ( xmax - xmin ) / (PLFLT) nx;
00388 dy = ( ymax - ymin ) / (PLFLT) ny;
00389
00390
00391 nnx = (PLINT) ceil( ( Dxmax - Dxmin ) / dx );
00392 nny = (PLINT) ceil( ( Dymax - Dymin ) / dy );
00393
00394
00395
00396
00397 xm = (PLINT) floor( ( Dxmin - xmin ) / dx );
00398 ym = (PLINT) floor( ( Dymin - ymin ) / dy );
00399
00400
00401 plAlloc2dGrid( &z, nnx, nny );
00402 zops = plf2ops_c();
00403
00404
00405
00406 ixx = -1;
00407 for ( ix = xm; ix < xm + nnx; ix++ )
00408 {
00409 ixx++; iyy = 0;
00410 for ( iy = ym; iy < ym + nny; iy++ )
00411 {
00412 z[ixx][iyy++] = idataops->get( idatap, ix, iy );
00413 }
00414 }
00415
00416
00417 copied = TRUE;
00418 }
00419
00420 plfimagefr( zops, (PLPointer) z, nnx, nny, Dxmin, Dxmax, Dymin, Dymax, zmin, zmax,
00421 data_min, data_max, NULL, NULL );
00422
00423
00424 if ( copied == TRUE )
00425 {
00426 plFree2dGrid( z, nnx, nny );
00427 }
00428 }