|
From: <and...@us...> - 2008-07-24 15:20:16
|
Revision: 8587
http://plplot.svn.sourceforge.net/plplot/?rev=8587&view=rev
Author: andrewross
Date: 2008-07-24 15:20:24 +0000 (Thu, 24 Jul 2008)
Log Message:
-----------
Fix java and python (untested) support for plimagefr. Update java example 20 consistent with
the C version.
Modified Paths:
--------------
trunk/bindings/java/PLStream.java
trunk/bindings/java/plplotjavac.i
trunk/bindings/swig-support/plplotcapi.i
trunk/examples/java/x20.java
Modified: trunk/bindings/java/PLStream.java
===================================================================
--- trunk/bindings/java/PLStream.java 2008-07-24 14:40:57 UTC (rev 8586)
+++ trunk/bindings/java/PLStream.java 2008-07-24 15:20:24 UTC (rev 8587)
@@ -405,9 +405,9 @@
plplotjavac.plimage(data, xmin, xmax, ymin, ymax, zmin, zmax, Dxmin, Dxmax, Dymin, Dymax);
}
-public void imagefr(double[][] data, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double valuemin, double valuemax, double[][] pltr, double[][] OBJECT_DATA) {
+public void imagefr(double[][] data, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double valuemin, double valuemax, double[][] pltr_im, double[][] OBJECT_DATA_im) {
if (set_stream() == -1) return;
- plplotjavac.plimagefr(data, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax, pltr, OBJECT_DATA);
+ plplotjavac.plimagefr(data, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax, pltr_im, OBJECT_DATA_im);
}
public void init() {
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2008-07-24 14:40:57 UTC (rev 8586)
+++ trunk/bindings/java/plplotjavac.i 2008-07-24 15:20:24 UTC (rev 8587)
@@ -1171,6 +1171,145 @@
return $jnicall;
}
+/* First of two object arrays, where we check X and Y with previous.
+ * Note this is the simplified Tcl-like approach to handling the xg
+ * and yg arrays. Later we would like to move to true call-back functions
+ * here instead like is done with the python interface. */
+/* This is the version for plimagefr where size is 1 larger than previous
+ * array */
+%typemap(in) pltr_func pltr_img {
+ jPLFLT **adat;
+ jobject *ai;
+ int nx = (*jenv)->GetArrayLength( jenv, $input );
+ int ny = -1;
+ int i, j;
+ ai = (jobject *) malloc( nx * sizeof(jobject) );
+ adat = (jPLFLT **) malloc( nx * sizeof(jPLFLT *) );
+
+ (*jenv)->EnsureLocalCapacity( jenv, nx );
+
+ for( i=0; i < nx; i++ )
+ {
+ ai[i] = (*jenv)->GetObjectArrayElement( jenv, $input, i );
+ adat[i] = (*jenv)->GetPLFLTArrayElements( jenv, ai[i], 0 );
+
+ if (ny == -1)
+ ny = (*jenv)->GetArrayLength( jenv, ai[i] );
+ else if (ny != (*jenv)->GetArrayLength( jenv, ai[i] )) {
+ printf( "Misshapen a array.\n" );
+ for( j=0; j <= i; j++ )
+ (*jenv)->ReleasePLFLTArrayElements( jenv, ai[j], adat[j], 0 );
+ free(adat);
+ free(ai);
+ return;
+ }
+ }
+
+ if( !((nx == Xlen+1 && ny == Ylen+1) || (nx == Xlen+1 && ny == 1))) {
+ printf( "Xlen = %d, nx = %d, Ylen = %d, ny = %d\n", Xlen, nx, Ylen, ny );
+ printf( "X vector or matrix must match matrix dimensions.\n" );
+ for( i=0; i < nx; i++ )
+ (*jenv)->ReleasePLFLTArrayElements( jenv, ai[i], adat[i], 0 );
+ free(adat);
+ free(ai);
+ return;
+ }
+ /* Store whether second dimension is unity. */
+ Alen = ny;
+ setup_array_2d_PLFLT( &xg, adat, nx, ny );
+ for( i=0; i < nx; i++ ) {
+ (*jenv)->ReleasePLFLTArrayElements( jenv, ai[i], adat[i], 0 );
+ (*jenv)->DeleteLocalRef(jenv, ai[i]);
+ }
+
+ free(adat);
+ free(ai);
+ $1 = pltr2;
+
+}
+
+%typemap(freearg) pltr_func pltr_img {
+ free(xg[0]);
+ free(xg);
+}
+%typemap(jni) pltr_func pltr_img "jobjectArray"
+%typemap(jtype) pltr_func pltr_img jPLFLTbracket2
+%typemap(jstype) pltr_func pltr_img jPLFLTbracket2
+%typemap(javain) pltr_func pltr_img "$javainput"
+%typemap(javaout) pltr_func pltr_img {
+ return $jnicall;
+}
+
+/* Second of two object arrays, where we check X and Y with previous object. */
+/* This is the version for plimagefr where size is 1 larger than previous
+ * array */
+%typemap(in) PLPointer OBJECT_DATA_img {
+ jPLFLT **adat;
+ jobject *ai;
+ int nx = (*jenv)->GetArrayLength( jenv, $input );
+ int ny = -1;
+ int i, j;
+ PLcGrid2 cgrid;
+ ai = (jobject *) malloc( nx * sizeof(jobject) );
+ adat = (jPLFLT **) malloc( nx * sizeof(jPLFLT *) );
+
+ (*jenv)->EnsureLocalCapacity( jenv, nx );
+
+ for( i=0; i < nx; i++ )
+ {
+ ai[i] = (*jenv)->GetObjectArrayElement( jenv, $input, i );
+ adat[i] = (*jenv)->GetPLFLTArrayElements( jenv, ai[i], 0 );
+
+ if (ny == -1)
+ ny = (*jenv)->GetArrayLength( jenv, ai[i] );
+ else if (ny != (*jenv)->GetArrayLength( jenv, ai[i] )) {
+ printf( "Misshapen a array.\n" );
+ for( j=0; j <= i; j++ )
+ (*jenv)->ReleasePLFLTArrayElements( jenv, ai[j], adat[j], 0 );
+ free(adat);
+ free(ai);
+ return;
+ }
+ }
+
+ if( !((nx == Xlen+1 && ny == Ylen+1) || (nx == Ylen+1 && ny == 1 && ny == Alen))) {
+ printf( "Xlen = %d, nx = %d, Ylen = %d, Alen = %d, ny = %d\n",
+ Xlen, nx, Ylen, Alen, ny );
+ printf( "Y vector or matrix must match matrix dimensions.\n" );
+ for( i=0; i < nx; i++ )
+ (*jenv)->ReleasePLFLTArrayElements( jenv, ai[i], adat[i], 0 );
+ free(adat);
+ free(ai);
+ return;
+ }
+ setup_array_2d_PLFLT( &yg, adat, nx, ny );
+ for( i=0; i < nx; i++ ) {
+ (*jenv)->ReleasePLFLTArrayElements( jenv, ai[i], adat[i], 0 );
+ (*jenv)->DeleteLocalRef(jenv, ai[i]);
+ }
+
+ free(adat);
+ free(ai);
+ cgrid.xg = xg;
+ cgrid.yg = yg;
+ cgrid.nx = nx;
+ cgrid.ny = ny;
+ $1 = &cgrid;
+
+}
+
+%typemap(freearg) PLPointer OBJECT_DATA_img {
+ free(yg[0]);
+ free(yg);
+}
+%typemap(jni) PLPointer OBJECT_DATA_img "jobjectArray"
+%typemap(jtype) PLPointer OBJECT_DATA_img jPLFLTbracket2
+%typemap(jstype) PLPointer OBJECT_DATA_img jPLFLTbracket2
+%typemap(javain) PLPointer OBJECT_DATA_img "$javainput"
+%typemap(javaout) PLPointer OBJECT_DATA_img {
+ return $jnicall;
+}
+
// Do not specify defined function or fill function from java. Instead
// specify NULL and plfill defaults in the interface C code.
%typemap(in, numinputs=0) defined_func df {
Modified: trunk/bindings/swig-support/plplotcapi.i
===================================================================
--- trunk/bindings/swig-support/plplotcapi.i 2008-07-24 14:40:57 UTC (rev 8586)
+++ trunk/bindings/swig-support/plplotcapi.i 2008-07-24 15:20:24 UTC (rev 8587)
@@ -171,8 +171,11 @@
#ifdef SWIG_PYTHON
#define SWIG_OBJECT_DATA PYOBJECT_DATA
+#define SWIG_OBJECT_DATA_img PYOBJECT_DATA
+#define pltr_img pltr
#else
#define SWIG_OBJECT_DATA OBJECT_DATA
+#define SWIG_OBJECT_DATA_img OBJECT_DATA_img
#endif
#ifdef SWIG_PYTHON
@@ -958,7 +961,7 @@
plimagefr( PLFLT **Matrix, PLINT nx, PLINT ny,
PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
PLFLT valuemin, PLFLT valuemax,
- pltr_func pltr, PLPointer SWIG_OBJECT_DATA);
+ pltr_func pltr_img, PLPointer SWIG_OBJECT_DATA_img);
#ifdef 0
/* Returns a list of file-oriented device names and their menu strings */
Modified: trunk/examples/java/x20.java
===================================================================
--- trunk/examples/java/x20.java 2008-07-24 14:40:57 UTC (rev 8586)
+++ trunk/examples/java/x20.java 2008-07-24 15:20:24 UTC (rev 8587)
@@ -108,7 +108,13 @@
int i, j, width, height, num_col;
int n[] = new int[1];
double img_f[][];
+ double img_min;
+ double img_max;
+ double maxmin[] = new double[2];
+ double x0, y0, dy, stretch;
+ double xg[][], yg[][];
+
/*
Bugs in plimage():
-at high magnifications, the left and right edge are ragged, try
@@ -252,6 +258,57 @@
pls.adv(0);
}
+ // Base the dynamic range on the image contents.
+ f2mnmx(img_f,width,height,maxmin);
+ img_max = maxmin[0];
+ img_min = maxmin[1];
+
+ // For java we use 2-d arrays to replace the pltr function
+ // even for the NULL case.
+ xg = new double[width+1][height+1];
+ yg = new double[width+1][height+1];
+
+ for (i = 0; i<=width; i++) {
+ for (j = 0; j<=height; j++) {
+ xg[i][j] = (double) i;
+ yg[i][j] = (double) j;
+ }
+ }
+ // Draw a saturated version of the original image. Only use
+ // the middle 50% of the image's full dynamic range.
+ pls.col0(2);
+ pls.env(0, width, 0, height, 1, -1);
+ pls.lab("", "", "Reduced dynamic range image example");
+ pls.imagefr(img_f, 0., (double) width, 0., (double) height, 0., 0.,
+ img_min + img_max * 0.25,
+ img_max - img_max * 0.25,
+ xg, yg);
+
+ // Draw a distorted version of the original image, showing its full dynamic range.
+ pls.env(0, width, 0, height, 1, -1);
+ pls.lab("", "", "Distorted image example");
+
+ x0 = 0.5*width;
+ y0 = 0.5*height;
+ dy = 0.5*height;
+ stretch = 0.5;
+
+ /* In C / C++ the following would work, with plimagefr directly calling
+ mypltr. For compatibilty with other language bindings the same effect
+ can be achieved by generating the transformed grid first and then
+ using pltr2. */
+ /* plimagefr(img_f, width, height, 0., width, 0., height, 0., 0., img_min, img_max, mypltr, (PLPointer) &stretch); */
+
+ for (i = 0; i<=width; i++) {
+ for (j = 0; j<=height; j++) {
+ xg[i][j] = x0 + (x0-i)*(1.0 - stretch*
+ Math.cos((j-y0)/dy*Math.PI*0.5));
+ yg[i][j] = j;
+ }
+ }
+
+ pls.imagefr(img_f, 0., (double) width, 0., (double) height, 0., 0., img_min, img_max, xg, yg);
+ pls.adv(0);
pls.end();
}
@@ -410,6 +467,22 @@
pls.scmap1l(true, pos, r, g, b);
}
+ // Calculate the minimum and maximum of a 2-d array
+ void f2mnmx(double [][] f, int nx, int ny, double[] fmaxmin)
+ {
+ int i, j;
+
+ fmaxmin[0] = f[0][0];
+ fmaxmin[1] = fmaxmin[0];
+
+ for (i = 0; i < nx; i++) {
+ for (j = 0; j < ny; j++) {
+ fmaxmin[0] = Math.max(fmaxmin[0], f[i][j]);
+ fmaxmin[1] = Math.min(fmaxmin[1], f[i][j]);
+ }
+ }
+ }
+
public static void main( String[] args ) {
new x20( args );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|