From: <and...@us...> - 2009-01-15 09:57:34
|
Revision: 9310 http://plplot.svn.sourceforge.net/plplot/?rev=9310&view=rev Author: andrewross Date: 2009-01-15 09:57:31 +0000 (Thu, 15 Jan 2009) Log Message: ----------- Implement plmap and plmeridians in java bindings. Add implementation of example 19. Add example 19 to standard java tests. Modified Paths: -------------- trunk/bindings/java/CMakeLists.txt trunk/bindings/java/PLStream.java trunk/bindings/java/plplotjavac.i trunk/bindings/swig-support/plplotcapi.i trunk/examples/java/x19.java trunk/plplot_test/test_java.sh.in Modified: trunk/bindings/java/CMakeLists.txt =================================================================== --- trunk/bindings/java/CMakeLists.txt 2009-01-14 21:22:14 UTC (rev 9309) +++ trunk/bindings/java/CMakeLists.txt 2009-01-15 09:57:31 UTC (rev 9310) @@ -53,6 +53,8 @@ JAVA_FILES_FULL ${JAVA_GEN_FILES_FULL} ${CMAKE_CURRENT_SOURCE_DIR}/PLStream.java +${CMAKE_CURRENT_SOURCE_DIR}/PLCallback.java + ) # Explicit full-path class dependencies for the foreach loop below which @@ -67,6 +69,11 @@ set(class_root ${CMAKE_CURRENT_BINARY_DIR}/plplot/core) set( +${class_root}/plplotjavacJNI.class_DEPENDS +${class_root}/PLCallback.class +) + +set( ${class_root}/PLGraphicsIn.class_DEPENDS ${class_root}/plplotjavacJNI.class ) @@ -81,6 +88,7 @@ ${class_root}/plplotjavacConstants.class ${class_root}/PLGraphicsIn.class ${class_root}/plplotjavacJNI.class +${class_root}/PLCallback.class ) set( @@ -88,6 +96,7 @@ ${class_root}/plplotjavacConstants.class ${class_root}/config.class ${class_root}/plplotjavac.class +${class_root}/PLCallback.class ) # This is currently the include list for swig, the C wrapper and the Modified: trunk/bindings/java/PLStream.java =================================================================== --- trunk/bindings/java/PLStream.java 2009-01-14 21:22:14 UTC (rev 9309) +++ trunk/bindings/java/PLStream.java 2009-01-15 09:57:31 UTC (rev 9310) @@ -445,6 +445,16 @@ plplotjavac.pllsty(lin); } +public void map(PLCallback mapform, String type, double minlong, double maxlong, double minlat, double maxlat) { + if (set_stream() == -1) return; + plplotjavac.plmap(mapform, type, minlong, maxlong, minlat, maxlat); +} + +public void meridians(PLCallback mapform, double dlong, double dlat, double minlong, double maxlong, double minlat, double maxlat) { + if (set_stream() == -1) return; + plplotjavac.plmeridians(mapform, dlong, dlat, minlong, maxlong, minlat, maxlat); +} + public void minMax2dGrid(double[][]f, double[] fmax, double[] fmin) { if (set_stream() == -1) return; plplotjavac.plMinMax2dGrid(f,fmax,fmin); Modified: trunk/bindings/java/plplotjavac.i =================================================================== --- trunk/bindings/java/plplotjavac.i 2009-01-14 21:22:14 UTC (rev 9309) +++ trunk/bindings/java/plplotjavac.i 2009-01-15 09:57:31 UTC (rev 9310) @@ -254,6 +254,48 @@ } } + +/* Setup java arrays (for callback functions) */ + +#ifdef PL_DOUBLE +#define jPLFLT jdouble +#define jPLFLTArray jdoubleArray +#define NewPLFLTArray NewDoubleArray +#define SetPLFLTArrayRegion SetDoubleArrayRegion +#define GetPLFLTArrayElements GetDoubleArrayElements +#define ReleasePLFLTArrayElements ReleaseDoubleArrayElements +#else +#define jPLFLT jfloat +#define jPLFLTArray jfloatArray +#define NewPLFLTArray NewFloatArray +#define SetPLFLTArrayRegion SetFloatArrayRegion +#define GetPLFLTArrayElements GetFloatArrayElements +#define ReleasePLFLTArrayElements ReleaseFloatArrayElements +#endif + +/* Create a jPLFLTArray and fill it from the C array dat */ +static jPLFLTArray +setup_java_array_1d_PLFLT( JNIEnv *jenv, PLFLT *dat, PLINT n) +{ + jPLFLTArray jadat = (*jenv)->NewPLFLTArray(jenv, n); + (*jenv)->SetPLFLTArrayRegion(jenv, jadat, 0, n, dat); + return jadat; +} + +/* Copy back data from jPLFLTArray to C array then release java array */ +static void +release_java_array_1d_PLFLT(JNIEnv *jenv, jPLFLTArray jadat, PLFLT *dat, PLINT n) +{ + PLINT i; + jPLFLT *jdata = (*jenv)->GetPLFLTArrayElements( jenv, jadat, 0 ); + for (i=0;i<n;i++) { + dat[i] = jdata[i]; + } + (*jenv)->ReleasePLFLTArrayElements( jenv, jadat, jdata, 0 ); +} + + + %} @@ -1033,6 +1075,7 @@ typedef PLINT (*defined_func)(PLFLT, PLFLT); typedef void (*fill_func)(PLINT, PLFLT*, PLFLT*); typedef void (*pltr_func)(PLFLT, PLFLT, PLFLT *, PLFLT*, PLPointer); + typedef void (*mapform_func)(PLINT, PLFLT *, PLFLT*); typedef PLFLT (*f2eval_func)(PLINT, PLINT, PLPointer); %} @@ -1103,6 +1146,46 @@ return $jnicall; } +%{ + + jobject mapformClass; + jmethodID mapformID; + JNIEnv *cbenv; + + /* C mapform callback function which calls the java + * mapform function in a PLCallback object. */ + void mapform_java(PLINT n, PLFLT *x, PLFLT *y) { + jPLFLTArray jx = setup_java_array_1d_PLFLT(cbenv,x,n); + jPLFLTArray jy = setup_java_array_1d_PLFLT(cbenv,y,n); + (*cbenv)->CallVoidMethod(cbenv,mapformClass, mapformID,jx,jy); + release_java_array_1d_PLFLT(cbenv,jx,x,n); + release_java_array_1d_PLFLT(cbenv,jy,y,n); + } +%} + + +/* Handle function pointers to mapform function using an java class */ +%typemap(in) mapform_func mapform { + + jobject obj = $input; + if (obj != NULL) { + jclass cls = (*jenv)->GetObjectClass(jenv,obj); + mapformID = (*jenv)->GetMethodID(jenv,cls, "mapform","([D[D)V" ); + mapformClass = obj; + cbenv = jenv; + $1 = mapform_java; + } + else { + $1 = NULL; + } + +} + +%typemap(jni) mapform_func "jobject" +%typemap(jtype) mapform_func "PLCallback" +%typemap(jstype) mapform_func "PLCallback" +%typemap(javain) mapform_func mapform "$javainput" + /* Second of two object arrays, where we check X and Y with previous object. */ %typemap(in) PLPointer OBJECT_DATA { jPLFLT **adat; Modified: trunk/bindings/swig-support/plplotcapi.i =================================================================== --- trunk/bindings/swig-support/plplotcapi.i 2009-01-14 21:22:14 UTC (rev 9309) +++ trunk/bindings/swig-support/plplotcapi.i 2009-01-15 09:57:31 UTC (rev 9310) @@ -931,19 +931,28 @@ PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, pltr_func pltr, PLPointer SWIG_OBJECT_DATA); + +#endif + +#ifdef SWIG_JAVA + /* plot continental outline in world coordinates */ void -plmap( void (*mapform)(PLINT, PLFLT *, PLFLT *), const char *type, +plmap( mapform_func mapform, const char *type, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat ); /* Plot the latitudes and longitudes on the background. */ void -plmeridians( void (*mapform)(PLINT, PLFLT *, PLFLT *), +plmeridians( mapform_func mapform, PLFLT dlong, PLFLT dlat, PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat ); +#endif + +#if 0 + void plfshade(f2eval_func, PLPointer SWIG_OBJECT_DATA, Modified: trunk/examples/java/x19.java =================================================================== --- trunk/examples/java/x19.java 2009-01-14 21:22:14 UTC (rev 9309) +++ trunk/examples/java/x19.java 2009-01-15 09:57:31 UTC (rev 9310) @@ -27,12 +27,88 @@ package plplot.examples; +import plplot.core.*; + +import java.lang.Math; + +class Mapform19 implements PLCallback { + + public void mapform(double[] x, double[] y) { + int i; + double xp, yp, radius; + for (i=0;i< x.length;i++) { + radius = 90.0-y[i]; + xp = radius * Math.cos(x[i] * Math.PI / 180.0); + yp = radius * Math.sin(x[i] * Math.PI / 180.0); + x[i] = xp; + y[i] = yp; + } + + + } + +} + class x19 { + PLStream pls = new PLStream(); + public static void main( String[] args ) { - System.out.println( "x19 not implemented yet." ); + new x19(args); } + + public x19 (String[] args) + { + double minx, maxx, miny,maxy; + PLCallback nullCallback = null; + + // Parse and process command line arguments. + pls.parseopts( args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM ); + + // Longitude (x) and latitude (y) + + miny = -70; + maxy = 80; + + // Initialize PLplot. + pls.init(); + // Cartesian plots + // Most of world + + minx = 190; + maxx = 190+360; + + pls.col0(1); + pls.env(minx, maxx, miny, maxy, 1, -1); + pls.map(nullCallback, "usaglobe", minx, maxx, miny, maxy); + + // The Americas + + minx = 190; + maxx = 340; + + pls.col0(1); + pls.env(minx, maxx, miny, maxy, 1, -1); + pls.map(nullCallback, "usaglobe", minx, maxx, miny, maxy); + + // Polar, Northern hemisphere + + // Create callback object containing mapform function + Mapform19 mapform19 = new Mapform19(); + + minx = 0; + maxx = 360; + + pls.env(-75., 75., -75., 75., 1, -1); + pls.map(mapform19,"globe", minx, maxx, miny, maxy); + + pls.lsty(2); + pls.meridians(mapform19,10.0, 10.0, 0.0, 360.0, -10.0, 80.0); + + pls.end(); + + } } //---------------------------------------------------------------------------// Modified: trunk/plplot_test/test_java.sh.in =================================================================== --- trunk/plplot_test/test_java.sh.in 2009-01-14 21:22:14 UTC (rev 9309) +++ trunk/plplot_test/test_java.sh.in 2009-01-15 09:57:31 UTC (rev 9310) @@ -31,7 +31,6 @@ # pushd $javadir; make; popd # Do the standard non-interactive examples. -# skip 19 because it is not implemented. # # Set up option to point to java bindings jar file and wrapper if needed. lang="j" @@ -45,7 +44,7 @@ PLPLOT_CLASSPATH=${javadir}:${PLPLOT_CLASSPATH} fi -for index in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 ; do +for index in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ; do if [ "$verbose_test" ] ; then echo "x${index}" fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |