129 #define NUMBER_BISECTIONS 10
131 #define linear( val1, val2, level ) ( ( level - val1 ) / ( val2 - val1 ) )
161 big_recl(
int *cond_code,
register int ny,
int dx,
int dy,
212 xmin, xmax, ymin, ymax,
213 clevel, nlevel, fill_width,
214 cont_color, cont_width,
242 PLFLT shade_min, shade_max, shade_color;
244 PLFLT init_width, color_min, color_max, color_range;
247 color_min = plsc->cmap1_min;
248 color_max = plsc->cmap1_max;
249 color_range = color_max - color_min;
251 for ( i = 0; i < nlevel - 1; i++ )
253 shade_min = clevel[i];
254 shade_max = clevel[i + 1];
255 shade_color = color_min + i / (
PLFLT) ( nlevel - 2 ) * color_range;
262 plfshade1( zops, zp, nx, ny, defined, xmin, xmax, ymin, ymax,
263 shade_min, shade_max,
264 1, shade_color, fill_width,
266 fill, rectangular,
pltr, pltr_data );
268 if ( cont_color > 0 && cont_width > 0 )
270 init_color = plsc->icol0;
271 init_width = plsc->width;
276 plfcont( zops->
f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel,
pltr, pltr_data );
289 x = (
PLFLT *) malloc( (
size_t) nx *
sizeof (
PLFLT ) );
291 plexit(
"plfshades: Out of memory for x" );
293 for ( i = 0; i < nx; i++ )
294 cgrid1.
xg[i] = xmin + ( xmax - xmin ) * (float) i / (
float) ( nx - 1 );
295 y = (
PLFLT *) malloc( (
size_t) ny *
sizeof (
PLFLT ) );
297 plexit(
"plfshades: Out of memory for y" );
299 for ( i = 0; i < ny; i++ )
300 cgrid1.
yg[i] = ymin + ( ymax - ymin ) * (float) i / (
float) ( ny - 1 );
301 plfcont( zops->
f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel,
302 pltr1, (
void *) &cgrid1 );
332 defined, nx, ny, xmin,
333 xmax, ymin, ymax, shade_min, shade_max,
334 sh_cmap, sh_color, sh_width,
335 min_color, min_width, max_color, max_width,
336 fill, rectangular,
pltr, pltr_data );
366 defined, nx, ny, xmin,
367 xmax, ymin, ymax, shade_min, shade_max,
368 sh_cmap, sh_color, sh_width,
369 min_color, min_width, max_color, max_width,
370 fill, rectangular,
pltr, pltr_data );
395 plshade_int( f2eval, f2eval_data, c2eval, c2eval_data,
397 nx, ny, xmin, xmax, ymin, ymax,
398 shade_min, shade_max, sh_cmap, sh_color, sh_width,
399 min_color, min_width, max_color, max_width,
400 fill, rectangular,
pltr, pltr_data );
429 defined, nx, ny, xmin,
430 xmax, ymin, ymax, shade_min, shade_max,
431 sh_cmap, sh_color, sh_width,
432 min_color, min_width, max_color, max_width,
433 fill, rectangular,
pltr, pltr_data );
482 PLINT n, slope = 0, ix, iy;
483 int count, i, j, nxny;
485 PLFLT x[8], y[8], xp[2], tx, ty, init_width;
490 if ( plsc->level < 3 )
492 plabort(
"plfshade: window must be set up first" );
496 if ( nx <= 0 || ny <= 0 )
498 plabort(
"plfshade: nx and ny must be positive" );
502 if ( shade_min >= shade_max )
504 plabort(
"plfshade: shade_max must exceed shade_min" );
508 if (
pltr == NULL && plsc->coordinate_transform == NULL )
511 int_val = shade_max - shade_min;
512 init_width = plsc->width;
533 plabort(
"plfshade: invalid color map selection" );
540 if ( ( a = (
PLFLT *) malloc( (
size_t) nxny *
sizeof (
PLFLT ) ) ) == NULL )
542 plabort(
"plfshade: unable to allocate memory for value array" );
546 for ( ix = 0; ix < nx; ix++ )
547 for ( iy = 0; iy < ny; iy++ )
548 a[iy + ix * ny] = f2eval( ix, iy, f2eval_data );
552 if ( ( c = (
int *) malloc( (
size_t) nxny *
sizeof (
int ) ) ) == NULL )
554 plabort(
"plfshade: unable to allocate memory for condition codes" );
563 dx = ( xmax -
xmin ) / ( nx - 1 );
564 dy = ( ymax -
ymin ) / ( ny - 1 );
570 for ( ix = 0; ix < nx - 1; ix++ )
572 for ( iy = 0; iy < ny - 1; iy++ )
574 count = c0[iy] + c0[iy + 1] + c1[iy] + c1[iy + 1];
578 if ( count >=
UNDEF )
580 if ( count == 4 *
POS )
582 if ( count == 4 *
NEG )
587 if ( count == 4 *
OK )
592 big_recl( c0 + iy, ny, nx - ix, ny - iy, &i, &j );
599 x[2] = x[3] = ix + i;
601 y[1] = y[2] = iy + j;
605 for ( i = 0; i < 4; i++ )
607 ( *pltr )( x[i], y[i], &tx, &ty, pltr_data );
614 for ( i = 0; i < 4; i++ )
616 x[i] = xmin + x[i] *
dx;
617 y[i] = ymin + y[i] *
dy;
629 n =
find_interval( a0[iy], a0[iy + 1], c0[iy], c0[iy + 1], xp );
630 for ( j = 0; j < n; j++ )
637 c0[iy + 1], c1[iy + 1], xp );
639 for ( j = 0; j < i; j++ )
641 x[j + n] = ix + xp[j];
646 i =
find_interval( a1[iy + 1], a1[iy], c1[iy + 1], c1[iy], xp );
647 for ( j = 0; j < i; j++ )
650 y[n + j] = iy + 1 - xp[j];
655 for ( j = 0; j < i; j++ )
657 x[n + j] = ix + 1 - xp[j];
664 for ( i = 0; i < n; i++ )
666 ( *pltr )( x[i], y[i], &tx, &ty, pltr_data );
673 for ( i = 0; i < n; i++ )
675 x[i] = xmin + x[i] *
dx;
676 y[i] = ymin + y[i] *
dy;
681 slope =
plctestez( a, nx, ny, ix, iy, shade_min );
683 slope =
plctestez( a, nx, ny, ix, iy, shade_max );
697 if (
fill != NULL && n > 0 )
703 fprintf( stderr,
"plfshade err n=%d !6", (
int) n );
704 if ( slope == 1 && c0[iy] ==
OK )
709 else if ( slope == 1 )
714 else if ( c0[iy + 1] ==
OK )
727 fprintf( stderr,
"plfshade err n=%d !8", (
int) n );
743 fprintf( stderr,
"plfshade err n=%d !7", (
int) n );
745 if ( ( c0[iy] ==
OK || c1[iy + 1] ==
OK ) && slope == 1 )
750 else if ( ( c0[iy + 1] ==
OK || c1[iy] ==
OK ) && slope == 0 )
756 else if ( c0[iy] ==
OK )
761 else if ( c0[iy + 1] ==
OK )
766 else if ( c1[iy + 1] ==
OK )
771 else if ( c1[iy] ==
OK )
778 fprintf( stderr,
"plfshade err logic case 024:042\n" );
782 fprintf( stderr,
"prog err switch\n" );
792 else if ( sh_cmap == 1 )
823 else if (
isnan( *a ) )
856 if ( c0 ==
NEG || c1 ==
POS )
869 if ( c0 ==
POS || c1 ==
NEG )
897 register PLINT n = 0;
947 xm = ( x1 + x2 ) / 2.;
948 ym = ( y1 + y2 ) / 2.;
950 if ( defined( xm, ym ) )
951 bisect( defined, niter - 1, xm, ym, x2, y2, xb, yb );
953 bisect( defined, niter - 1, x1, y1, xm, ym, xb, yb );
977 plabort(
"exfill: Not enough points in object" );
981 if ( defined == NULL )
983 ( *fill )( n, x, y );
992 PLINT is_defined = defined( x[im1], y[im1] );
997 if ( ( xx = (
PLFLT *) malloc( 2 * (
size_t) n *
sizeof (
PLFLT ) ) ) == NULL )
998 plexit(
"exfill: out of memory for xx" );
999 if ( ( yy = (
PLFLT *) malloc( 2 * (
size_t) n *
sizeof (
PLFLT ) ) ) == NULL )
1000 plexit(
"exfill: out of memory for yy." );
1002 for ( i = 0; i < n; i++ )
1005 if ( defined( x[i], y[i] ) )
1013 x[i], y[i], x[im1], y[im1], &xb, &yb );
1031 x[im1], y[im1], x[i], y[i], &xb, &yb );
1072 #define COND( x, y ) cond_code[x * ny + y]
1079 register int i, x, y;
1088 while ( ok_x || ok_y )
1100 cond = &
COND( 0, y );
1101 for ( i = 0; i < x; i++ )
1122 cond = &
COND( x, 0 );
1123 for ( i = 0; i < y; i++ )
1125 if ( *cond++ !=
OK )
1143 for ( i = 1; i < x; i++ )
1145 cond = &
COND( i, 1 );
1146 for ( j = 1; j < y; j++ )
1175 pljoin( x[
min_pts[0]], y[min_pts[0]], x[min_pts[1]], y[min_pts[1]] );
1178 pljoin( x[min_pts[2]], y[min_pts[2]], x[min_pts[3]],
1193 pljoin( x[
max_pts[0]], y[max_pts[0]], x[max_pts[1]], y[max_pts[1]] );
1196 pljoin( x[max_pts[2]], y[max_pts[2]], x[max_pts[3]],
1235 #define X( a, b ) ( x[a * 4 + b] )
1236 #define POSITIVE_SLOPE (PLINT) 1
1237 #define NEGATIVE_SLOPE (PLINT) 0
1238 #define RATIO_SQ 6.0
1244 double t[4], sorted[4], temp;
1246 sorted[0] = t[0] =
X( 1, 1 );
1247 sorted[1] = t[1] =
X( 2, 2 );
1248 sorted[2] = t[2] =
X( 1, 2 );
1249 sorted[3] = t[3] =
X( 2, 1 );
1251 for ( j = 1; j < 4; j++ )
1255 while ( i >= 0 && sorted[i] > temp )
1257 sorted[i + 1] = sorted[i];
1260 sorted[i + 1] = temp;
1266 if ( temp < sorted[1] )
1269 for ( i = 0; i < 4; i++ )
1278 if ( temp > sorted[2] )
1281 for ( i = 0; i < 4; i++ )
1307 for ( i = 0; i < 4; i++ )
1311 ii =
MIN( ii, nx - 1 );
1312 for ( j = 0; j < 4; j++ )
1316 jj =
MIN( jj, ny - 1 );
1317 x[i][j] = a[ii * ny + jj];
1320 return plctest( &( x[0][0] ), level );