## [Plplot-cvs] SF.net SVN: plplot:[10642] trunk/src/plshade.c

 [Plplot-cvs] SF.net SVN: plplot:[10642] trunk/src/plshade.c From: - 2009-11-29 07:44:36 ```Revision: 10642 http://plplot.svn.sourceforge.net/plplot/?rev=10642&view=rev Author: airwin Date: 2009-11-29 07:44:30 +0000 (Sun, 29 Nov 2009) Log Message: ----------- Slight code cleanup; use macro to define the number of bisections. Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2009-11-29 00:45:30 UTC (rev 10641) +++ trunk/src/plshade.c 2009-11-29 07:44:30 UTC (rev 10642) @@ -132,6 +132,7 @@ #define POS 8 #define OK 0 #define UNDEF 64 +#define NUMBER_BISECTIONS 10 #define linear( val1, val2, level ) (( level - val1 ) / ( val2 - val1 )) @@ -932,10 +933,10 @@ if ( !is_inside ) { if ( i > 0 ) - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[i], y[i], x[i - 1], y[i - 1], &xb, &yb ); else - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[i], y[i], x[n - 1], y[n - 1], &xb, &yb ); xx[count] = xb; yy[count++] = yb; @@ -949,10 +950,10 @@ if ( is_inside ) { if ( i > 0 ) - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[i - 1], y[i - 1], x[i], y[i], &xb, &yb ); else - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[n - 1], y[n - 1], x[i], y[i], &xb, &yb ); xx[count] = xb; yy[count++] = yb; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```

 [Plplot-cvs] SF.net SVN: plplot:[10642] trunk/src/plshade.c From: - 2009-11-29 07:44:36 ```Revision: 10642 http://plplot.svn.sourceforge.net/plplot/?rev=10642&view=rev Author: airwin Date: 2009-11-29 07:44:30 +0000 (Sun, 29 Nov 2009) Log Message: ----------- Slight code cleanup; use macro to define the number of bisections. Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2009-11-29 00:45:30 UTC (rev 10641) +++ trunk/src/plshade.c 2009-11-29 07:44:30 UTC (rev 10642) @@ -132,6 +132,7 @@ #define POS 8 #define OK 0 #define UNDEF 64 +#define NUMBER_BISECTIONS 10 #define linear( val1, val2, level ) (( level - val1 ) / ( val2 - val1 )) @@ -932,10 +933,10 @@ if ( !is_inside ) { if ( i > 0 ) - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[i], y[i], x[i - 1], y[i - 1], &xb, &yb ); else - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[i], y[i], x[n - 1], y[n - 1], &xb, &yb ); xx[count] = xb; yy[count++] = yb; @@ -949,10 +950,10 @@ if ( is_inside ) { if ( i > 0 ) - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[i - 1], y[i - 1], x[i], y[i], &xb, &yb ); else - bisect( defined, 10, + bisect( defined, NUMBER_BISECTIONS, x[n - 1], y[n - 1], x[i], y[i], &xb, &yb ); xx[count] = xb; yy[count++] = yb; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[10681] trunk/src/plshade.c From: - 2009-12-04 21:53:08 ```Revision: 10681 http://plplot.svn.sourceforge.net/plplot/?rev=10681&view=rev Author: airwin Date: 2009-12-04 21:52:58 +0000 (Fri, 04 Dec 2009) Log Message: ----------- exfill: comment it, clean up the logic, and make it more robust without changing the fundamental algorithm for filling a polygon where some polygon points are in an undefined region where you want to accurately plot the edges of the defined region. Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2009-12-04 16:51:12 UTC (rev 10680) +++ trunk/src/plshade.c 2009-12-04 21:52:58 UTC (rev 10681) @@ -892,8 +892,8 @@ return; } - xm = ( x1 + x2 ) / 2; - ym = ( y1 + y2 ) / 2; + xm = ( x1 + x2 ) / 2.; + ym = ( y1 + y2 ) / 2.; if ( defined( xm, ym )) bisect( defined, niter - 1, xm, ym, x2, y2, xb, yb ); @@ -904,66 +904,92 @@ /*----------------------------------------------------------------------*\ * exfill() * - * Draws a polygon from points in x[] and y[] by taking into account - * eventual exclusions - \*----------------------------------------------------------------------*/ + * Fills a polygon from points in x[] and y[] with all points in + * undefined regions dropped and replaced by points at the bisected + * edge of the defined region. + * Note, undefined regions that are confined to the areas between polygon + * points are completely ignored. Also, a range of undefined polygon points + * are simply replaced with a straight line with accurately bisected end + * points. So this routine can produce problematic plotted results + * if the polygon is not a lot smaller than the typical resolution of + * the defined region. + \*----------------------------------------------------------------------*/ static void exfill( void ( *fill )( PLINT, PLFLT *, PLFLT * ), PLINT ( *defined )( PLFLT, PLFLT ), int n, PLFLT *x, PLFLT *y ) { + if ( n < 3 ) + { + plabort( "exfill: Not enough points in object" ); + return; + } + if ( defined == NULL ) ( *fill )( n, x, y ); else { - PLFLT xx[16]; - PLFLT yy[16]; + PLFLT *xx; + PLFLT *yy; PLFLT xb, yb; PLINT count = 0; - PLINT is_inside = defined( x[n - 1], y[n - 1] ); + PLINT im1 = n-1; + PLINT is_defined = defined( x[im1], y[im1] ); PLINT i; + /* Slightly less than 2 n points are required for xx, yy, but + * allocate room for 2 n to be safe. */ + if((xx = (PLFLT *) malloc( 2 * n * sizeof ( PLFLT ))) == NULL ) + plexit("exfill: out of memory for xx"); + if((yy = (PLFLT *) malloc( 2 * n * sizeof ( PLFLT ))) == NULL ) + plexit("exfill: out of memory for yy."); + for ( i = 0; i < n; i++ ) { + /* is_defined tells whether im1 point was in defined region. */ if ( defined( x[i], y[i] )) { - if ( !is_inside ) + if ( !is_defined ) { - if ( i > 0 ) - bisect( defined, NUMBER_BISECTIONS, - x[i], y[i], x[i - 1], y[i - 1], &xb, &yb ); - else - bisect( defined, NUMBER_BISECTIONS, - x[i], y[i], x[n - 1], y[n - 1], &xb, &yb ); + /* Cross from undefined (at im1) to defined region. + * Bisect for the first point inside the defined region + * and add it to xx, yy. */ + bisect( defined, NUMBER_BISECTIONS, + x[i], y[i], x[im1], y[im1], &xb, &yb ); xx[count] = xb; yy[count++] = yb; } + /* x[i], y[i] known to be in defined region so add this + * point to xx, yy. */ xx[count] = x[i]; yy[count++] = y[i]; - is_inside = 1; + is_defined = 1; } else { - if ( is_inside ) + if ( is_defined ) { - if ( i > 0 ) - bisect( defined, NUMBER_BISECTIONS, - x[i - 1], y[i - 1], x[i], y[i], &xb, &yb ); - else - bisect( defined, NUMBER_BISECTIONS, - x[n - 1], y[n - 1], x[i], y[i], &xb, &yb ); + /* Cross from defined (at im1) to undefined region. + * Bisect for the last point in the defined region and + * add it to xx, yy. */ + bisect( defined, NUMBER_BISECTIONS, + x[im1], y[im1], x[i], y[i], &xb, &yb ); xx[count] = xb; yy[count++] = yb; - is_inside = 0; + is_defined = 0; } } + im1 = i; } - if ( count ) + if ( count >= 3 ) ( *fill )( count, xx, yy ); + + free ( xx ); + free ( yy ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[10682] trunk/src/plshade.c From: - 2009-12-05 02:05:22 ```Revision: 10682 http://plplot.svn.sourceforge.net/plplot/?rev=10682&view=rev Author: airwin Date: 2009-12-05 02:05:14 +0000 (Sat, 05 Dec 2009) Log Message: ----------- Style previous changes. Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2009-12-04 21:52:58 UTC (rev 10681) +++ trunk/src/plshade.c 2009-12-05 02:05:14 UTC (rev 10682) @@ -913,7 +913,7 @@ * points. So this routine can produce problematic plotted results * if the polygon is not a lot smaller than the typical resolution of * the defined region. - \*----------------------------------------------------------------------*/ + \*----------------------------------------------------------------------*/ static void exfill( void ( *fill )( PLINT, PLFLT *, PLFLT * ), @@ -935,17 +935,17 @@ PLFLT *xx; PLFLT *yy; PLFLT xb, yb; - PLINT count = 0; - PLINT im1 = n-1; + PLINT count = 0; + PLINT im1 = n - 1; PLINT is_defined = defined( x[im1], y[im1] ); PLINT i; /* Slightly less than 2 n points are required for xx, yy, but * allocate room for 2 n to be safe. */ - if((xx = (PLFLT *) malloc( 2 * n * sizeof ( PLFLT ))) == NULL ) - plexit("exfill: out of memory for xx"); - if((yy = (PLFLT *) malloc( 2 * n * sizeof ( PLFLT ))) == NULL ) - plexit("exfill: out of memory for yy."); + if (( xx = (PLFLT *) malloc( 2 * n * sizeof ( PLFLT ))) == NULL ) + plexit( "exfill: out of memory for xx" ); + if (( yy = (PLFLT *) malloc( 2 * n * sizeof ( PLFLT ))) == NULL ) + plexit( "exfill: out of memory for yy." ); for ( i = 0; i < n; i++ ) { @@ -954,9 +954,9 @@ { if ( !is_defined ) { - /* Cross from undefined (at im1) to defined region. - * Bisect for the first point inside the defined region - * and add it to xx, yy. */ + /* Cross from undefined (at im1) to defined region. + * Bisect for the first point inside the defined region + * and add it to xx, yy. */ bisect( defined, NUMBER_BISECTIONS, x[i], y[i], x[im1], y[im1], &xb, &yb ); xx[count] = xb; @@ -966,20 +966,20 @@ * point to xx, yy. */ xx[count] = x[i]; yy[count++] = y[i]; - is_defined = 1; + is_defined = 1; } else { if ( is_defined ) { - /* Cross from defined (at im1) to undefined region. - * Bisect for the last point in the defined region and - * add it to xx, yy. */ + /* Cross from defined (at im1) to undefined region. + * Bisect for the last point in the defined region and + * add it to xx, yy. */ bisect( defined, NUMBER_BISECTIONS, x[im1], y[im1], x[i], y[i], &xb, &yb ); xx[count] = xb; yy[count++] = yb; - is_defined = 0; + is_defined = 0; } } im1 = i; @@ -988,8 +988,8 @@ if ( count >= 3 ) ( *fill )( count, xx, yy ); - free ( xx ); - free ( yy ); + free( xx ); + free( yy ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[10895] trunk/src/plshade.c From: - 2010-04-08 21:28:28 ```Revision: 10895 http://plplot.svn.sourceforge.net/plplot/?rev=10895&view=rev Author: hezekiahcarty Date: 2010-04-08 21:28:21 +0000 (Thu, 08 Apr 2010) Log Message: ----------- plshade* functions may receive a pltr function without pltr_data In particular, bindings to languages other than C may never set pltr_data. OCaml does not, for example. This would cause the plshade functions to always assume a rectangular transform, regardless of what the user specifies. Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2010-04-08 19:12:58 UTC (rev 10894) +++ trunk/src/plshade.c 2010-04-08 21:28:21 UTC (rev 10895) @@ -514,7 +514,7 @@ return; } - if ( pltr == NULL || pltr_data == NULL ) + if ( pltr == NULL ) rectangular = 1; int_val = shade_max - shade_min; @@ -609,7 +609,7 @@ y[0] = y[3] = iy; y[1] = y[2] = iy + j; - if ( pltr && pltr_data ) + if ( pltr ) { for ( i = 0; i < 4; i++ ) { @@ -668,7 +668,7 @@ } n += i; - if ( pltr && pltr_data ) + if ( pltr ) { for ( i = 0; i < n; i++ ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[10896] trunk/src/plshade.c From: - 2010-04-08 21:45:18 ```Revision: 10896 http://plplot.svn.sourceforge.net/plplot/?rev=10896&view=rev Author: hezekiahcarty Date: 2010-04-08 21:45:12 +0000 (Thu, 08 Apr 2010) Log Message: ----------- Remove one more potentially erroneous pltr_data check. This was missed in my last commit. Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2010-04-08 21:28:21 UTC (rev 10895) +++ trunk/src/plshade.c 2010-04-08 21:45:12 UTC (rev 10896) @@ -272,7 +272,7 @@ init_width = plsc->width; plcol0( cont_color ); plwid( cont_width ); - if ( pltr && pltr_data ) + if ( pltr ) { plfcont( zops->f2eval, zp, nx, ny, 1, nx, 1, ny, clevel, nlevel, pltr, pltr_data ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[10959] trunk/src/plshade.c From: - 2010-05-01 16:16:31 ```Revision: 10959 http://plplot.svn.sourceforge.net/plplot/?rev=10959&view=rev Author: airwin Date: 2010-05-01 16:16:24 +0000 (Sat, 01 May 2010) Log Message: ----------- Reinstate pltr_data tests for NULL that were removed by revision 10895. It turns out those tests are essential for the python and tcl bindings to work properly. Revision Links: -------------- http://plplot.svn.sourceforge.net/plplot/?rev=10895&view=rev Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2010-05-01 15:58:15 UTC (rev 10958) +++ trunk/src/plshade.c 2010-05-01 16:16:24 UTC (rev 10959) @@ -514,7 +514,7 @@ return; } - if ( pltr == NULL && plsc->coordinate_transform == NULL ) + if ( (pltr == NULL && plsc->coordinate_transform == NULL) || pltr_data == NULL ) rectangular = 1; int_val = shade_max - shade_min; @@ -609,7 +609,7 @@ y[0] = y[3] = iy; y[1] = y[2] = iy + j; - if ( pltr ) + if ( pltr && pltr_data ) { for ( i = 0; i < 4; i++ ) { @@ -668,7 +668,7 @@ } n += i; - if ( pltr ) + if ( pltr && pltr_data ) { for ( i = 0; i < n; i++ ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[10965] trunk/src/plshade.c From: - 2010-05-03 05:06:39 ```Revision: 10965 http://plplot.svn.sourceforge.net/plplot/?rev=10965&view=rev Author: airwin Date: 2010-05-03 05:06:32 +0000 (Mon, 03 May 2010) Log Message: ----------- Now that NULL pltr is accessible to both Python and Tcl and used where appropriately in all Python and Tcl examples, then drop tests for pltr_data == NULL to get the behaviour you ordinarily would get with pltr == NULL. As Hez has stated: "it doesn't make sense to me in a general context to require that both arguments [pltr and pltr_data] are non-NULL - if the pltr function does not require any extra data to be passed in then it seems strange to require a non-NULL pltr_data argument. This holds for any language." Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2010-05-03 05:02:24 UTC (rev 10964) +++ trunk/src/plshade.c 2010-05-03 05:06:32 UTC (rev 10965) @@ -514,7 +514,7 @@ return; } - if ( (pltr == NULL && plsc->coordinate_transform == NULL) || pltr_data == NULL ) + if ( pltr == NULL && plsc->coordinate_transform == NULL ) rectangular = 1; int_val = shade_max - shade_min; @@ -609,7 +609,7 @@ y[0] = y[3] = iy; y[1] = y[2] = iy + j; - if ( pltr && pltr_data ) + if ( pltr ) { for ( i = 0; i < 4; i++ ) { @@ -668,7 +668,7 @@ } n += i; - if ( pltr && pltr_data ) + if ( pltr ) { for ( i = 0; i < n; i++ ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[12280] trunk/src/plshade.c From: - 2012-11-23 21:25:46 ```Revision: 12280 http://plplot.svn.sourceforge.net/plplot/?rev=12280&view=rev Author: andrewross Date: 2012-11-23 21:25:40 +0000 (Fri, 23 Nov 2012) Log Message: ----------- Properly block out points which are set to NaN when using plshade. Thanks to Phil Rosenberg for this suggestion. Modified Paths: -------------- trunk/src/plshade.c Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2012-11-23 09:58:38 UTC (rev 12279) +++ trunk/src/plshade.c 2012-11-23 21:25:40 UTC (rev 12280) @@ -822,6 +822,8 @@ *cond++ = NEG; else if ( *a > sh_max ) *cond++ = POS; + else if ( isnan(*a) ) //check for nans and set cond to undefined + *cond++ = UNDEF; else *cond++ = OK; a++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```