From: Andrew R. <and...@us...> - 2009-02-23 10:04:09
|
Hez, Thanks for this. You've got me started thinking about something that has been on my todo list for a long time. Actually, it may not be as much work as I had assumed. It is not just plimage that has to worry about these issue - at least plline and plcont / plshade have problems too. plgriddata also doesn't handle nan's well. A couple of comments about your patch. 1) isnan / isinf are only defined in the C99 standard and so are not available for all compilers. We already have a test for isnan in place and provide a replacement. We would need to do something similar with isinf. 2) I'm not sure in principle whether a max / min function should exclude +/- inf values. These do behave correctly with respect to ordering, i.e. -inf < real / double number < inf. Of course from the point of view of plotting you want the finite max/min, which is perhaps a different thing. NaN's return false for any comparison and hence should be filtered out anyway by the test. Can you leave this with me for now and I'll try and integrate it along with further NaN / inf changes in the near future? Thanks Andrew On Sat, Feb 21, 2009 at 10:24:17PM -0500, Hezekiah M. Carty wrote: > PLplot developers, > > The attached patch is an attempt at making plimagefr and plimage nan > infinite value friendly by skipping those values in plotted images. > To facilitate this the patch also modifies plMinMax2dGrid in an > attempt to avoid nan and infinite values. I think the isnan check in > the > > The attached OCaml program illustrates the issue. Without this patch, > it crashes with a segfault on my system (64bit Ubuntu Intrepid). With > the patch, the neg_infinity and infinity values are not plotted and > the image colors are scaled from -1.0 to 1.0. > > I don't know what sort of cross-platform compatibility issues may > exist with handling nan and infinite floating point values this way. > If there are not any then I think this would be a useful addition to > PLplot. > > Hez > > -- > Hezekiah M. Carty > Graduate Research Assistant > University of Maryland > Department of Atmospheric and Oceanic Science > diff --git a/src/pdfutils.c b/src/pdfutils.c > index b96cde2..e95a3d1 100644 > --- a/src/pdfutils.c > +++ b/src/pdfutils.c > @@ -915,13 +915,22 @@ plMinMax2dGrid(PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmax, PLFLT *fmin) > { > int i, j; > PLFLT m, M; > + PLFLT tmp; > > - M = m = f[0][0]; > + tmp = f[0][0]; > + if (isnan(tmp) || isinf(tmp)) { > + M = -HUGE_VAL; > + m = HUGE_VAL; > + } > + else > + M = m = f[0][0]; > > for (i = 0; i < nx; i++) { > for (j = 0; j < ny; j++) { > - if (f[i][j] > M) M = f[i][j]; > - if (f[i][j] < m) m = f[i][j]; > + tmp = f[i][j]; > + if (isnan(tmp) || isinf(tmp)) continue; > + if (tmp > M) M = tmp; > + if (tmp < m) m = tmp; > } > } > *fmax = M; > diff --git a/src/plimage.c b/src/plimage.c > index 4060793..5901825 100644 > --- a/src/plimage.c > +++ b/src/plimage.c > @@ -234,7 +234,7 @@ c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny, > } > else { > datum = idata[ix][iy]; > - if (datum < zmin || datum > zmax) { > + if (isnan(datum) || isinf(datum) || datum < zmin || datum > zmax) { > /* Set to a guaranteed-not-to-plot value */ > z[ix * ny + iy] = COLOR_NO_PLOT; > } > open Plplot > > let () = > let image = [|[|neg_infinity; -1.0; 0.0; 1.0; infinity|]|] in > plsdev "xwin"; > plinit (); > plenv 0. 1. 0. 1. 1 0; > plimage image 0. 1. 0. 1. 0.0 0.0 0. 1. 0. 1.; > plend (); > () > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Plplot-devel mailing list > Plp...@li... > https://lists.sourceforge.net/lists/listinfo/plplot-devel |