Attached is an initial attempt at adding coordinate transform support
to plimagefr, similar to what is available in the plshade*, plcont,
plmap and plmeridians functions. It is an unfinished attempt because
it does not cover a few cases:
1. The xwin driver has "dev_fastimg" support and therefore uses a
separate rendering path in the underlying image routines. This
dev_fastimg path is not covered by this patch. This rendering path
seem to get rather deep in to the plplot internals, so the required
changes may take me a while to track down. The xcairo device does not
use this though and seems to work properly. I have not tested other
devices yet.
2. I do not know how to handle the rdbuf_image function. It calls
plP_image, which should receive the pltr callback and pltr_data
pointers. I do not know how to pass these in properly though. Is it
something I add the to PLStream argument somehow?
One option for solving (1) is to drop the dev_fastimg rendering path.
I think xwin may be the only device which supports this, at least
under Linux. Dropping dev_fastimg may also solve (2), but I would
have to study that further to know for certain as the interactions
between these functions are not clear to me yet.
Any thoughts on these ideas? As far as I can tell, the dev_fastimg
flag is only referenced in the plimage* functions, and it loses a
large portion of its utility when coordinate transforms are added.
Thanks,
Hez
--
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
diff --git a/include/plplot.h b/include/plplot.h
index adf7e09..b638b16 100644
--- a/include/plplot.h
+++ b/include/plplot.h
@@ -1460,9 +1460,11 @@ c_plstripd(PLINT id);
PLDLLIMPEXP void
c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
- PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
- PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax,
- PLFLT valuemin, PLFLT valuemax);
+ PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
+ PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax,
+ PLFLT valuemin, PLFLT valuemax,
+ void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
+ PLPointer pltr_data);
/* plots a 2d image (or a matrix too large for plshade() ) - colors
automatically scaled */
diff --git a/include/plplotP.h b/include/plplotP.h
index 3d9f8fe..795c9ef 100644
--- a/include/plplotP.h
+++ b/include/plplotP.h
@@ -874,7 +874,8 @@ plP_fill(short *x, short *y, PLINT npts);
/* draw image */
void
-plP_image(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny, PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy, unsigned short zmin, unsigned short zmax);
+plP_image(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny, PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy, unsigned short zmin, unsigned short zmax,
+ void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data);
/* End of page */
@@ -957,8 +958,10 @@ plInBuildTree();
void
plimageslow(short *x, short *y, unsigned short *data, PLINT nx, PLINT ny,
- PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
- unsigned short zmin, unsigned short zmax);
+ PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
+ unsigned short zmin, unsigned short zmax,
+ void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
+ PLPointer pltr_data);
typedef struct {
PLFLT xmin, ymin, dx, dy;} IMG_DT;
diff --git a/src/plbuf.c b/src/plbuf.c
index f95b4e4..b231988 100644
--- a/src/plbuf.c
+++ b/src/plbuf.c
@@ -659,7 +659,9 @@ rdbuf_image(PLStream *pls)
rd_data(pls, dev_iy, sizeof(short) * npts);
rd_data(pls, dev_z, sizeof(unsigned short) * (nptsX-1)*(nptsY-1));
- plP_image(dev_ix, dev_iy, dev_z, nptsX, nptsY, xmin, ymin, dx, dy, dev_zmin, dev_zmax);
+ // TODO Add proper pltr support here?
+ plwarn("WARNING: rdbuf_image: user definable pltr not support, falling back on pltr0");
+ plP_image(dev_ix, dev_iy, dev_z, nptsX, nptsY, xmin, ymin, dx, dy, dev_zmin, dev_zmax, pltr0, NULL);
free(dev_ix);
free(dev_iy);
diff --git a/src/plcore.c b/src/plcore.c
index 27b5317..295ccd0 100644
--- a/src/plcore.c
+++ b/src/plcore.c
@@ -3427,7 +3427,8 @@ return(ret);
\*--------------------------------------------------------------------------*/
void
-plP_image(short *x, short *y, unsigned short *z , PLINT nx, PLINT ny, PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy, unsigned short zmin, unsigned short zmax)
+plP_image(short *x, short *y, unsigned short *z , PLINT nx, PLINT ny, PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy, unsigned short zmin, unsigned short zmax,
+ void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), PLPointer pltr_data)
{
PLINT i, npts;
short *xscl, *yscl;
@@ -3437,7 +3438,7 @@ plP_image(short *x, short *y, unsigned short *z , PLINT nx, PLINT ny, PLFLT xmin
if (plsc->dev_fastimg == 0) {
plimageslow(x, y, z, nx-1, ny-1,
- xmin, ymin, dx, dy, zmin, zmax);
+ xmin, ymin, dx, dy, zmin, zmax, pltr, pltr_data);
return ;
}
diff --git a/src/plimage.c b/src/plimage.c
index 67be368..a87ab39 100644
--- a/src/plimage.c
+++ b/src/plimage.c
@@ -69,55 +69,74 @@ enabledisplay()
}
-
+/* NOTE: Unlike the plshade routines, pltr IS required here. This may change
+ * in the future since this is not part of the public API. But anything which
+ * uses plimageslow at this time MUST provide a pltr callback.
+ */
void
plimageslow(short *x, short *y, unsigned short *data, PLINT nx, PLINT ny,
- PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
- unsigned short zmin, unsigned short zmax)
+ PLFLT xmin, PLFLT ymin, PLFLT dx, PLFLT dy,
+ unsigned short zmin, unsigned short zmax,
+ void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
+ PLPointer pltr_data)
{
+ /* TODO Some of the casts in here may be extraneous... my C is a little
+ rusty. */
+ // Indices
PLINT ix, iy, i;
+ // Float coordinates
PLFLT xf[4], yf[4];
+ // Short coordinates
short xs[5], ys[5];
+ // Translated (by pltr) coordinates
+ PLFLT tx, ty;
+ // The corners of a single filled region
int corners[4];
- unsigned short col;
+ // The color to use in the fill
+ unsigned short color;
for (ix = 0; ix < nx ; ix++) {
for (iy = 0; iy < ny ; iy++) {
+ // Only plot values within in the zmin to zmax range
+ color = data[ix * ny + iy];
+ if (color < zmin || color > zmax)
+ continue;
- col = data[ix*ny+iy];
- /* only plot points within zmin/zmax range */
- if (col < zmin || col > zmax)
- continue;
-
- plcol1(col/(float)USHRT_MAX);
+ // The color value has to be scaled to 0.0 -> 1.0 plcol1 color values
+ plcol1(color / (float)USHRT_MAX);
if (plsc->plbuf_read == 1) {
- /* buffer read, is a replot to a slow device. */
-
- corners[0] = ix*(ny+1)+iy; /* [ix][iy] */
- corners[1] = (ix+1)*(ny+1)+iy; /* [ix+1][iy] */
- corners[2] = (ix+1)*(ny+1)+iy+1; /* [ix+1][iy+1] */
- corners[3] = ix*(ny+1)+iy+1; /* [ix][iy+1] */
-
- for (i = 0; i < 4; i++) {
- xs[i] = x[corners[i]];
- ys[i] = y[corners[i]];
- }
- xs[4] = xs[0]; ys[4] = ys[0];
- plP_fill(xs, ys, 5);
-
- } else {
-
- xf[0] = xf[1] = ix;
- xf[2] = xf[3] = ix+1;
- yf[0] = yf[3] = iy;
- yf[1] = yf[2] = iy+1;
-
- for (i = 0; i < 4; i++) {
- xf[i] = xmin + xf[i]*dx;
- yf[i] = ymin + yf[i]*dy;
- }
- plfill(4, xf, yf);
+ // buffer read, is a replot to a slow device.
+
+ corners[0] = ix * (ny+1) + iy; // [ix][iy]
+ corners[1] = (ix+1) * (ny+1) + iy; // [ix+1][iy]
+ corners[2] = (ix+1) * (ny+1) + iy + 1; // [ix+1][iy+1]
+ corners[3] = ix * (ny+1) + iy + 1; // [ix][iy+1]
+
+ for (i = 0; i < 4; i++) {
+ // Translate the points, and cast back to short
+ (*pltr) ((float)x[corners[i]], (float)y[corners[i]], &tx, &ty, pltr_data);
+ xs[i] = (short)tx;
+ ys[i] = (short)ty;
+ }
+ xs[4] = xs[0]; ys[4] = ys[0];
+ plP_fill(xs, ys, 5);
+
+ }
+ else {
+
+ xf[0] = xf[1] = ix;
+ xf[2] = xf[3] = ix+1;
+ yf[0] = yf[3] = iy;
+ yf[1] = yf[2] = iy+1;
+
+ for (i = 0; i < 4; i++) {
+ // Translate the points
+ (*pltr) ((float)(xmin + xf[i] * dx), (float)(ymin + yf[i] * dy), &tx, &ty, pltr_data);
+ xf[i] = tx;
+ yf[i] = ty;
+ }
+ plfill(4, xf, yf);
}
}
}
@@ -175,7 +194,9 @@ void
c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax,
- PLFLT valuemin, PLFLT valuemax)
+ PLFLT valuemin, PLFLT valuemax,
+ void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer),
+ PLPointer pltr_data)
{
PLINT nnx, nny, ix, iy, ixx, iyy, xm, ym;
PLFLT dx, dy;
@@ -204,24 +225,24 @@ c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
dx = (xmax - xmin) / (nx - 1);
dy = (ymax - ymin) / (ny - 1);
- nnx = (Dxmax-Dxmin)/dx + 1;
- nny = (Dymax-Dymin)/dy + 1;
+ nnx = (Dxmax - Dxmin) / dx + 1;
+ nny = (Dymax - Dymin) / dy + 1;
- if ((Zf = (unsigned short *) malloc(nny*nnx*sizeof(unsigned short)))==NULL)
- {
- plexit("plimage: Insufficient memory");
- }
+ if ((Zf = (unsigned short *) malloc(nny * nnx * sizeof(unsigned short))) == NULL) {
+ plexit("plimage: Insufficient memory");
+ }
- xm = floor((Dxmin-xmin)/dx); ym = floor((Dymin-ymin)/dy);
+ xm = floor((Dxmin - xmin) / dx);
+ ym = floor((Dymin - ymin) / dy);
// Go through the image values and scale them to fit in an
// unsigned short range.
// Any values greater than valuemax are set to valuemax,
// and values less than valuemin are set to valuemin.
- ixx=-1;
- for (ix=xm; ix<xm+nnx; ix++) {
+ ixx = -1;
+ for (ix = xm; ix < xm + nnx; ix++) {
ixx++; iyy=0;
- for (iy=ym; iy<ym+nny; iy++) {
+ for (iy = ym; iy < ym + nny; iy++) {
datum = idata[ix][iy];
if (datum < valuemin) {
datum = valuemin;
@@ -229,7 +250,7 @@ c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
else if (datum > valuemax) {
datum = valuemax;
}
- Zf[ixx*nny+iyy++] =
+ Zf[ixx * nny + iyy++] =
(datum - valuemin) / (valuemax - valuemin) * USHRT_MAX;
}
}
@@ -255,24 +276,24 @@ c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
/* The X and Y arrays has size nnx*nny */
nnx++; nny++;
- if (((Xf = (short *) malloc(nny*nnx*sizeof(short)))==NULL)||
- ((Yf = (short *) malloc(nny*nnx*sizeof(short)))==NULL))
- {
- plexit("plimage: Insufficient memory");
- }
+ if (((Xf = (short *) malloc(nny * nnx * sizeof(short))) == NULL) ||
+ ((Yf = (short *) malloc(nny * nnx * sizeof(short))) == NULL))
+ {
+ plexit("plimage: Insufficient memory");
+ }
/* adjust the step for the X/Y arrays */
- dx = dx*(nx-1)/nx;
- dy = dy*(ny-1)/ny;
+ dx = dx * (nx - 1) / nx;
+ dy = dy * (ny - 1) / ny;
for (ix = 0; ix < nnx; ix++) {
for (iy = 0; iy < nny; iy++) {
- Xf[ix*nny+iy] = plP_wcpcx(xmin + ix*dx);
- Yf[ix*nny+iy] = plP_wcpcy(ymin + iy*dy);
+ Xf[ix * nny + iy] = plP_wcpcx(xmin + ix * dx);
+ Yf[ix * nny + iy] = plP_wcpcy(ymin + iy * dy);
}
}
- plP_image(Xf, Yf, Zf, nnx, nny, xmin, ymin, dx, dy, szmin, szmax);
+ plP_image(Xf, Yf, Zf, nnx, nny, xmin, ymin, dx, dy, szmin, szmax, pltr, pltr_data);
free(Xf);
free(Yf);
@@ -305,8 +326,8 @@ c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny,
void
c_plimage(PLFLT **idata, PLINT nx, PLINT ny,
- PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
- PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax)
+ PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
+ PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax)
{
PLINT ix, iy;
PLFLT data_min, data_max, iz;
@@ -319,14 +340,14 @@ c_plimage(PLFLT **idata, PLINT nx, PLINT ny,
for (iy = 0; iy < ny; iy++) {
iz = idata[ix][iy];
if (data_max < iz)
- data_max = iz;
+ data_max = iz;
if (data_min > iz)
- data_min = iz;
+ data_min = iz;
}
}
// Call plimagefr with the value -> color range mapped to the minimum
// and maximum values in idata.
plimagefr(idata, nx, ny, xmin, xmax, ymin, ymax, zmin, zmax,
- Dxmin, Dxmax, Dymin, Dymax, data_min, data_max);
+ Dxmin, Dxmax, Dymin, Dymax, data_min, data_max, pltr0, NULL);
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel