131 #define NUMBER_BISECTIONS 10
133 #define linear( val1, val2, level ) ( ( level - val1 ) / ( val2 - val1 ) )
214 xmin, xmax, ymin, ymax,
215 clevel, nlevel, fill_width,
216 cont_color, cont_width,
244 PLFLT shade_min, shade_max, shade_color;
246 PLFLT init_width, color_min, color_max, color_range;
249 color_min = plsc->cmap1_min;
250 color_max = plsc->cmap1_max;
251 color_range = color_max - color_min;
253 for ( i = 0; i < nlevel - 1; i++ )
255 shade_min = clevel[i];
256 shade_max = clevel[i + 1];
257 shade_color = color_min + i / (
PLFLT) ( nlevel - 2 ) * color_range;
264 plfshade1( zops, zp, nx, ny, defined, xmin, xmax, ymin, ymax,
265 shade_min, shade_max,
266 1, shade_color, fill_width,
268 fill, rectangular,
pltr, pltr_data );
270 if ( cont_color > 0 && cont_width > 0 )
272 init_color = plsc->icol0;
273 init_width = plsc->width;
278 plfcont( zops->
f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel,
pltr, pltr_data );
291 x = (
PLFLT *) malloc( (
size_t) nx *
sizeof (
PLFLT ) );
293 plexit(
"plfshades: Out of memory for x" );
295 for ( i = 0; i <
nx; i++ )
296 cgrid1.
xg[i] = xmin + ( xmax - xmin ) * (float) i / (
float) ( nx - 1 );
297 y = (
PLFLT *) malloc( (
size_t) ny *
sizeof (
PLFLT ) );
299 plexit(
"plfshades: Out of memory for y" );
301 for ( i = 0; i <
ny; i++ )
302 cgrid1.
yg[i] = ymin + ( ymax - ymin ) * (float) i / (
float) ( ny - 1 );
303 plfcont( zops->
f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel,
304 pltr1, (
void *) &cgrid1 );
334 defined, nx, ny, xmin,
335 xmax, ymin, ymax, shade_min, shade_max,
336 sh_cmap, sh_color, sh_width,
337 min_color, min_width, max_color, max_width,
338 fill, rectangular,
pltr, pltr_data );
368 defined, nx, ny, xmin,
369 xmax, ymin, ymax, shade_min, shade_max,
370 sh_cmap, sh_color, sh_width,
371 min_color, min_width, max_color, max_width,
372 fill, rectangular,
pltr, pltr_data );
397 plshade_int( f2eval, f2eval_data, c2eval, c2eval_data,
399 nx, ny, xmin, xmax, ymin, ymax,
400 shade_min, shade_max, sh_cmap, sh_color, sh_width,
401 min_color, min_width, max_color, max_width,
402 fill, rectangular,
pltr, pltr_data );
431 defined, nx, ny, xmin,
432 xmax, ymin, ymax, shade_min, shade_max,
433 sh_cmap, sh_color, sh_width,
434 min_color, min_width, max_color, max_width,
435 fill, rectangular,
pltr, pltr_data );
484 PLINT n, slope = 0, ix, iy;
485 int count, i, j, nxny;
487 PLFLT x[8],
y[8], xp[2], tx, ty, init_width;
492 if ( plsc->level < 3 )
494 plabort(
"plfshade: window must be set up first" );
498 if ( nx <= 0 || ny <= 0 )
500 plabort(
"plfshade: nx and ny must be positive" );
504 if ( shade_min >= shade_max )
506 plabort(
"plfshade: shade_max must exceed shade_min" );
510 if (
pltr == NULL && plsc->coordinate_transform == NULL )
513 int_val = shade_max - shade_min;
514 init_width = plsc->width;
535 plabort(
"plfshade: invalid color map selection" );
542 if ( ( a = (
PLFLT *) malloc( (
size_t) nxny *
sizeof (
PLFLT ) ) ) == NULL )
544 plabort(
"plfshade: unable to allocate memory for value array" );
548 for ( ix = 0; ix <
nx; ix++ )
549 for ( iy = 0; iy <
ny; iy++ )
550 a[iy + ix * ny] = f2eval( ix, iy, f2eval_data );
554 if ( ( c = (
int *) malloc( (
size_t) nxny *
sizeof (
int ) ) ) == NULL )
556 plabort(
"plfshade: unable to allocate memory for condition codes" );
565 dx = ( xmax -
xmin ) / ( nx - 1 );
566 dy = ( ymax -
ymin ) / ( ny - 1 );
572 for ( ix = 0; ix < nx - 1; ix++ )
574 for ( iy = 0; iy < ny - 1; iy++ )
576 count = c0[iy] + c0[iy + 1] + c1[iy] + c1[iy + 1];
580 if ( count >=
UNDEF )
582 if ( count == 4 *
POS )
584 if ( count == 4 *
NEG )
589 if ( count == 4 *
OK )
594 big_recl( c0 + iy, ny, nx - ix, ny - iy, &i, &j );
601 x[2] = x[3] = ix + i;
603 y[1] = y[2] = iy + j;
607 for ( i = 0; i < 4; i++ )
609 ( *pltr )( x[i], y[i], &tx, &ty, pltr_data );
616 for ( i = 0; i < 4; i++ )
618 x[i] = xmin + x[i] *
dx;
619 y[i] = ymin + y[i] *
dy;
631 n =
find_interval( a0[iy], a0[iy + 1], c0[iy], c0[iy + 1], xp );
632 for ( j = 0; j < n; j++ )
639 c0[iy + 1], c1[iy + 1], xp );
641 for ( j = 0; j < i; j++ )
643 x[j + n] = ix + xp[j];
648 i =
find_interval( a1[iy + 1], a1[iy], c1[iy + 1], c1[iy], xp );
649 for ( j = 0; j < i; j++ )
652 y[n + j] = iy + 1 - xp[j];
657 for ( j = 0; j < i; j++ )
659 x[n + j] = ix + 1 - xp[j];
666 for ( i = 0; i < n; i++ )
668 ( *pltr )( x[i], y[i], &tx, &ty, pltr_data );
675 for ( i = 0; i < n; i++ )
677 x[i] = xmin + x[i] *
dx;
678 y[i] = ymin + y[i] *
dy;
683 slope =
plctestez( a, nx, ny, ix, iy, shade_min );
685 slope =
plctestez( a, nx, ny, ix, iy, shade_max );
699 if ( fill != NULL && n > 0 )
700 exfill( fill, defined, n, x, y );
705 fprintf( stderr,
"plfshade err n=%d !6", (
int) n );
706 if ( slope == 1 && c0[iy] ==
OK )
709 exfill( fill, defined, n, x, y );
711 else if ( slope == 1 )
716 else if ( c0[iy + 1] ==
OK )
719 exfill( fill, defined, n, x, y );
729 fprintf( stderr,
"plfshade err n=%d !8", (
int) n );
745 fprintf( stderr,
"plfshade err n=%d !7", (
int) n );
747 if ( ( c0[iy] ==
OK || c1[iy + 1] ==
OK ) && slope == 1 )
750 exfill( fill, defined, n, x, y );
752 else if ( ( c0[iy + 1] ==
OK || c1[iy] ==
OK ) && slope == 0 )
755 exfill( fill, defined, n, x, y );
758 else if ( c0[iy] ==
OK )
763 else if ( c0[iy + 1] ==
OK )
768 else if ( c1[iy + 1] ==
OK )
773 else if ( c1[iy] ==
OK )
780 fprintf( stderr,
"plfshade err logic case 024:042\n" );
784 fprintf( stderr,
"prog err switch\n" );
794 else if ( sh_cmap == 1 )
825 else if (
isnan( *a ) )
858 if ( c0 ==
NEG || c1 ==
POS )
871 if ( c0 ==
POS || c1 ==
NEG )
899 register PLINT n = 0;
949 xm = ( x1 + x2 ) / 2.;
950 ym = ( y1 + y2 ) / 2.;
952 if ( defined( xm, ym ) )
953 bisect( defined, niter - 1, xm, ym, x2, y2, xb, yb );
955 bisect( defined, niter - 1, x1, y1, xm, ym, xb, yb );
979 plabort(
"exfill: Not enough points in object" );
983 if ( defined == NULL )
985 ( *fill )( n,
x,
y );
994 PLINT is_defined = defined( x[im1], y[im1] );
999 if ( ( xx = (
PLFLT *) malloc( 2 * (
size_t) n *
sizeof (
PLFLT ) ) ) == NULL )
1000 plexit(
"exfill: out of memory for xx" );
1001 if ( ( yy = (
PLFLT *) malloc( 2 * (
size_t) n *
sizeof (
PLFLT ) ) ) == NULL )
1002 plexit(
"exfill: out of memory for yy." );
1004 for ( i = 0; i < n; i++ )
1007 if ( defined( x[i], y[i] ) )
1015 x[i], y[i], x[im1], y[im1], &xb, &yb );
1033 x[im1], y[im1], x[i], y[i], &xb, &yb );
1074 #define COND( x, y ) cond_code[x * ny + y]
1081 register int i,
x,
y;
1090 while ( ok_x || ok_y )
1102 cond = &
COND( 0, y );
1103 for ( i = 0; i <
x; i++ )
1124 cond = &
COND( x, 0 );
1125 for ( i = 0; i <
y; i++ )
1127 if ( *cond++ !=
OK )
1145 for ( i = 1; i <
x; i++ )
1147 cond = &
COND( i, 1 );
1148 for ( j = 1; j <
y; j++ )
1177 pljoin( x[
min_pts[0]], y[min_pts[0]], x[min_pts[1]], y[min_pts[1]] );
1180 pljoin( x[min_pts[2]], y[min_pts[2]], x[min_pts[3]],
1195 pljoin( x[
max_pts[0]], y[max_pts[0]], x[max_pts[1]], y[max_pts[1]] );
1198 pljoin( x[max_pts[2]], y[max_pts[2]], x[max_pts[3]],
1237 #define X( a, b ) ( x[a * 4 + b] )
1238 #define POSITIVE_SLOPE (PLINT) 1
1239 #define NEGATIVE_SLOPE (PLINT) 0
1240 #define RATIO_SQ 6.0
1246 double t[4], sorted[4], temp;
1248 sorted[0] = t[0] =
X( 1, 1 );
1249 sorted[1] = t[1] =
X( 2, 2 );
1250 sorted[2] = t[2] =
X( 1, 2 );
1251 sorted[3] = t[3] =
X( 2, 1 );
1253 for ( j = 1; j < 4; j++ )
1257 while ( i >= 0 && sorted[i] > temp )
1259 sorted[i + 1] = sorted[i];
1262 sorted[i + 1] = temp;
1268 if ( temp < sorted[1] )
1271 for ( i = 0; i < 4; i++ )
1280 if ( temp > sorted[2] )
1283 for ( i = 0; i < 4; i++ )
1309 for ( i = 0; i < 4; i++ )
1313 ii =
MIN( ii, nx - 1 );
1314 for ( j = 0; j < 4; j++ )
1318 jj =
MIN( jj, ny - 1 );
1319 x[i][j] = a[ii * ny + jj];
1322 return plctest( &( x[0][0] ), level );
void plfshade1(PLF2OPS zops, PLPointer zp, PLINT nx, PLINT ny, PLINT(*defined)(PLFLT, PLFLT), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, PLFLT sh_color, PLFLT sh_width, PLINT min_color, PLFLT min_width, PLINT max_color, PLFLT max_width, void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT rectangular, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
void PLFLT PLINT PLINT PLFLT PLFLT PLFLT PLFLT PLINT PLINT PLINT PLFLT PLFLT PLINT PLFLT PLINT const PLINT const char *const PLINT nx
PLFLT plf2eval(PLINT ix, PLINT iy, PLPointer plf2eval_data)
#define linear(val1, val2, level)
void plfcont(PLFLT(*f2eval)(PLINT, PLINT, PLPointer), PLPointer f2eval_data, PLINT nx, PLINT ny, PLINT kx, PLINT lx, PLINT ky, PLINT ly, const PLFLT *clevel, PLINT nlevel, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
void c_plshades(const PLFLT *const *a, PLINT nx, PLINT ny, PLINT(*defined)(PLFLT, PLFLT), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, const PLFLT *clevel, PLINT nlevel, PLFLT fill_width, PLINT cont_color, PLFLT cont_width, void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT rectangular, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
static void set_cond(register int *cond, register PLFLT *a, register PLINT n)
void PLFLT PLINT PLINT PLFLT x
void PLFLT PLINT PLINT PLFLT PLFLT PLFLT PLFLT PLINT PLINT PLINT PLFLT PLFLT PLINT PLFLT PLINT const PLINT const char *const PLINT const char *const const PLFLT const PLINT const PLINT const PLFLT * a
static PLINT plctest(PLFLT *x, PLFLT level)
static void selected_polygon(void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT(*defined)(PLFLT, PLFLT), const PLFLT *x, const PLFLT *y, PLINT v1, PLINT v2, PLINT v3, PLINT v4)
void c_plshade1(const PLFLT *a, PLINT nx, PLINT ny, PLINT(*defined)(PLFLT, PLFLT), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, PLFLT sh_color, PLFLT sh_width, PLINT min_color, PLFLT min_width, PLINT max_color, PLFLT max_width, void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT rectangular, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
PLFLT(* f2eval)(PLINT ix, PLINT iy, PLPointer p)
#define NUMBER_BISECTIONS
static void pltr(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data)
static PLINT plctestez(PLFLT *a, PLINT nx, PLINT ny, PLINT ix, PLINT iy, PLFLT level)
static void plshade_int(PLFLT(*f2eval)(PLINT, PLINT, PLPointer), PLPointer f2eval_data, PLFLT(*c2eval)(PLINT, PLINT, PLPointer), PLPointer c2eval_data, PLINT(*defined)(PLFLT, PLFLT), PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, PLFLT sh_color, PLFLT sh_width, PLINT min_color, PLFLT min_width, PLINT max_color, PLFLT max_width, void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT rectangular, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
void PLFLT PLINT PLINT PLFLT PLFLT y
PLFLT plf2eval1(PLINT ix, PLINT iy, PLPointer plf2eval_data)
static void draw_boundary(PLINT slope, PLFLT *x, PLFLT *y)
void PLFLT PLINT PLINT PLFLT PLFLT PLFLT PLFLT PLINT PLINT PLINT PLFLT PLFLT PLINT cont_color
void plabort(const char *errormsg)
static void bisect(PLINT(*defined)(PLFLT, PLFLT), PLINT niter, PLFLT x1, PLFLT y1, PLFLT x2, PLFLT y2, PLFLT *xb, PLFLT *yb)
static void exfill(void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT(*defined)(PLFLT, PLFLT), int n, const PLFLT *x, const PLFLT *y)
void PLFLT PLINT PLINT PLFLT PLFLT PLFLT PLFLT PLINT PLINT PLINT PLFLT PLFLT PLINT PLFLT cont_width
void plfshade(PLFLT(*f2eval)(PLINT, PLINT, PLPointer), PLPointer f2eval_data, PLFLT(*c2eval)(PLINT, PLINT, PLPointer), PLPointer c2eval_data, PLINT nx, PLINT ny, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, PLFLT sh_color, PLFLT sh_width, PLINT min_color, PLFLT min_width, PLINT max_color, PLFLT max_width, void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT rectangular, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
static void big_recl(int *cond_code, register int ny, int dx, int dy, int *ix, int *iy)
static int find_interval(PLFLT a0, PLFLT a1, PLINT c0, PLINT c1, PLFLT *x)
void plfshades(PLF2OPS zops, PLPointer zp, PLINT nx, PLINT ny, PLINT(*defined)(PLFLT, PLFLT), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, const PLFLT *clevel, PLINT nlevel, PLFLT fill_width, PLINT cont_color, PLFLT cont_width, void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT rectangular, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
dx
if { $zoomopts($this,1) == 0 } then {
void c_plshade(const PLFLT *const *a, PLINT nx, PLINT ny, PLINT(*defined)(PLFLT, PLFLT), PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, PLFLT sh_color, PLFLT sh_width, PLINT min_color, PLFLT min_width, PLINT max_color, PLFLT max_width, void(*fill)(PLINT, const PLFLT *, const PLFLT *), PLINT rectangular, void(*pltr)(PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
void plexit(const char *errormsg)