From: <ai...@us...> - 2009-11-26 19:07:18
|
Revision: 10628 http://plplot.svn.sourceforge.net/plplot/?rev=10628&view=rev Author: airwin Date: 2009-11-26 19:07:08 +0000 (Thu, 26 Nov 2009) Log Message: ----------- Rename pointinpolygon as PLP_pointinpolygon that is accessible from all of the PLplot library and which has PLINT arguments changed to PLFLT arguments. The plan is to use PLP_pointinpolygon to help define the polygon limits of plshades when it is used for a software fallback for plgradient. Implement pointinpolygon (still defined statically within plline.c) as a PLINT argument wrapper of PLP_pointinpolygon. These changes make no difference for example 25 results which depend on pointinpolygon. Modified Paths: -------------- trunk/include/plplotP.h trunk/src/plline.c Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-11-24 18:43:49 UTC (rev 10627) +++ trunk/include/plplotP.h 2009-11-26 19:07:08 UTC (rev 10628) @@ -916,6 +916,9 @@ PLDLLIMPEXP void plRotationShear( PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride ); +/* Test whether a point is in a polygon. */ +int +plP_pointinpolygon( PLINT n, PLFLT *x, PLFLT *y, PLFLT xp, PLFLT yp ); /* Driver calls */ Modified: trunk/src/plline.c =================================================================== --- trunk/src/plline.c 2009-11-24 18:43:49 UTC (rev 10627) +++ trunk/src/plline.c 2009-11-26 19:07:08 UTC (rev 10628) @@ -56,7 +56,7 @@ /* Determines if a point is inside a polygon or not */ static int -pointinpolygon( int n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ); +pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ); /*----------------------------------------------------------------------*\ * void pljoin() @@ -1429,23 +1429,53 @@ /*----------------------------------------------------------------------*\ * int pointinpolygon() * - * Returns 1 if the point is inside the polygon, 0 otherwise - * Note: - * Points on the polygon are considered to be outside + * PLINT wrapper for plP_pointinpolygon. \*----------------------------------------------------------------------*/ static int -pointinpolygon( int n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ) +pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ) { + int i, return_value; + PLFLT *xflt, *yflt; + if(( xflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) + { + plexit( "pointinpolygon: Insufficient memory" ); + } + if(( yflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) + { + plexit( "pointinpolygon: Insufficient memory" ); + } + for ( i = 0; i < n; i++ ) + { + xflt[i] = (PLFLT) x[i]; + yflt[i] = (PLFLT) y[i]; + } + return_value = PLP_pointinpolygon( n, xflt, yflt, (PLFLT) xp, (PLFLT) yp ); + free( xflt ); + free( yflt ); + return return_value; +} +/*----------------------------------------------------------------------*\ + * int PLP_pointinpolygon() + * + * Returns 1 if the point is inside the polygon, 0 otherwise + * Notes: + * Points on the polygon are considered to be outside. + * This "Ray casting algorithm" has been described in + * http://en.wikipedia.org/wiki/Point_in_polygon. + * Logic still needs to be inserted to take care of the "ray passes + * through vertex" problem in a numerically robust way. + \*----------------------------------------------------------------------*/ + +int +PLP_pointinpolygon( PLINT n, PLFLT *x, PLFLT *y, PLFLT xp, PLFLT yp ) +{ int i; int count_crossings; - PLFLT x1, y1, x2, y2, xpp, ypp, xout, yout, xmax; + PLFLT x1, y1, x2, y2, xout, yout, xmax; PLFLT xvp, yvp, xvv, yvv, xv1, yv1, xv2, yv2; PLFLT inprod1, inprod2; - xpp = (PLFLT) xp; - ypp = (PLFLT) yp; - count_crossings = 0; @@ -1470,25 +1500,22 @@ /* Determine for each side whether the line segment between * our two points crosses the vertex */ - xpp = (PLFLT) xp; - ypp = (PLFLT) yp; + xvp = xp - xout; + yvp = yp - yout; - xvp = xpp - xout; - yvp = ypp - yout; - for ( i = 0; i < n; i++ ) { - x1 = (PLFLT) x[i]; - y1 = (PLFLT) y[i]; + x1 = x[i]; + y1 = y[i]; if ( i < n - 1 ) { - x2 = (PLFLT) x[i + 1]; - y2 = (PLFLT) y[i + 1]; + x2 = x[i + 1]; + y2 = y[i + 1]; } else { - x2 = (PLFLT) x[0]; - y2 = (PLFLT) y[0]; + x2 = x[0]; + y2 = y[0]; } /* Skip zero-length segments */ @@ -1512,11 +1539,11 @@ } /* Line through the two vertices: - * Are xout and xpp on either side? */ + * Are xout and xp on either side? */ xvv = x2 - x1; yvv = y2 - y1; - xv1 = xpp - x1; - yv1 = ypp - y1; + xv1 = xp - x1; + yv1 = yp - y1; xv2 = xout - x1; yv2 = yout - y1; inprod1 = xv1 * yvv - yv1 * xvv; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-11-27 01:54:04
|
Revision: 10630 http://plplot.svn.sourceforge.net/plplot/?rev=10630&view=rev Author: airwin Date: 2009-11-27 01:53:55 +0000 (Fri, 27 Nov 2009) Log Message: ----------- Experimental initial implementation of plgradient to plot a gradient (defined with cmap1) inside a clipping boundary polygon defined by the user. Currently only a software fallback (rather than native device driver gradient where applicable) is implemented. That fallback uses plshades to implement the gradient with the defined callback (4th argument of plshades) to exclude regions outside the polygon. However, that defined callback is not working at the moment. For that reason, I have temporarily replaced it with NULL. As a result this version is useful for seeing the full extent of the plshades result without clipping at the polygon boundary. Modified Paths: -------------- trunk/include/plplot.h trunk/include/plstrm.h trunk/src/CMakeLists.txt trunk/src/plline.c Added Paths: ----------- trunk/src/plgradient.c Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2009-11-26 22:53:23 UTC (rev 10629) +++ trunk/include/plplot.h 2009-11-27 01:53:55 UTC (rev 10630) @@ -611,6 +611,7 @@ #define plglevel c_plglevel #define plgpage c_plgpage #define plgra c_plgra +#define plgradient c_plgradient #define plgriddata c_plgriddata #define plgspa c_plgspa #define plgstrm c_plgstrm @@ -1044,6 +1045,12 @@ PLDLLIMPEXP void c_plgra( void ); +/* Draw gradient in polygon. */ + +PLDLLIMPEXP void +c_plgradient( PLINT n, PLFLT *x, PLFLT *y, + PLFLT fmin, PLFLT fmax, PLFLT angle ); + /* grid irregularly sampled data */ PLDLLIMPEXP void Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2009-11-26 22:53:23 UTC (rev 10629) +++ trunk/include/plstrm.h 2009-11-27 01:53:55 UTC (rev 10630) @@ -489,6 +489,16 @@ * of the transformation between broken-down and continuous time used * in the qsastime library. * + **************************************************************************** + * + * Gradient variables. + * + * n_polygon Number of vertex points in the polygon defining the + * boundary of the gradient. + * x_polygon Pointer to array of x vertex points in the polygon + * defining the boundary of the gradient. + * y_polygon Pointer to array of y vertex points in the polygon + * defining the boundary of the gradient. \*--------------------------------------------------------------------------*/ #define PL_MAX_CMAP1CP 256 @@ -731,6 +741,12 @@ * the qsastime library. */ QSASConfig *qsasconfig; + + /* The next three variables define the polygon boundary used + * in the software fallback for the gradient. */ + PLINT n_polygon; + PLFLT *x_polygon; + PLFLT *y_polygon; } PLStream; /*--------------------------------------------------------------------------*\ Modified: trunk/src/CMakeLists.txt =================================================================== --- trunk/src/CMakeLists.txt 2009-11-26 22:53:23 UTC (rev 10629) +++ trunk/src/CMakeLists.txt 2009-11-27 01:53:55 UTC (rev 10630) @@ -31,6 +31,7 @@ pldeprecated.c pldtik.c plfill.c + plgradient.c plfreetype.c plgset.c plhist.c Added: trunk/src/plgradient.c =================================================================== --- trunk/src/plgradient.c (rev 0) +++ trunk/src/plgradient.c 2009-11-27 01:53:55 UTC (rev 10630) @@ -0,0 +1,186 @@ +/* $Id$ + * + * Implement linear gradients for PLplot. + * + * Copyright (C) 2009 Alan W. Irwin + * + * This file is part of PLplot. + * + * PLplot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Library Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * PLplot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with PLplot; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "plplotP.h" + +/* software fallback for gradient. */ +static void +plgradient_soft( PLINT n, PLFLT *x, PLFLT *y, + PLFLT fmin, PLFLT fmax, PLFLT angle ); + +/* define where plshades plots gradient for software fallback for + * gradient. */ + +static int +gradient_defined( PLFLT x, PLFLT y ); + +/*----------------------------------------------------------------------*\ + * void plgradient() + * + * Draws a linear gradient at an angle relative to the increasing x + * direction for the polygon bounded by the x and y vertices. x, and + * y are expressed in world coordinates, and angle (in the world + * coordinate system) is expressed in degrees. The gradient is + * expressed using colour and transparency information from cmap1. + * fmin >= 0. and fmax <= 1. give the range of independent variable of + * cmap1 that is used for the gradient corresponding to the range of + * the polygon in the direction specified by angle. + \*----------------------------------------------------------------------*/ + +void +c_plgradient( PLINT n, PLFLT *x, PLFLT *y, + PLFLT fmin, PLFLT fmax, PLFLT angle ) +{ + if ( plsc->level < 3 ) + { + plabort( "plgradient: Please set up window first" ); + return; + } + if ( n < 3 ) + { + plabort( "plgradient: Not enough vertices in polygon" ); + return; + } + + /* For now this is the only method, but once at least one device driver + * implements a native linear gradient for a device, this will become + * the software fallback method for devices that don't have + * native linear gradient capability. */ + plgradient_soft( n, x, y, fmin, fmax, angle ); +} + +/*----------------------------------------------------------------------*\ + * void plgradient_soft() + * + * Software fallback for gradient. See c_plgradient for an explanation + * of the arguments. + \*----------------------------------------------------------------------*/ + +void +plgradient_soft( PLINT n, PLFLT *x, PLFLT *y, + PLFLT fmin, PLFLT fmax, PLFLT angle ) +{ + PLFLT xrot, xrot_min, xrot_max, cosangle, sinangle; + PLFLT xmin, xmax, ymin, ymax; + PLFLT **z, *edge; + PLINT i; + + if ( n < 3 ) + { + plabort( "plgradient_soft: Not enough vertices in polygon" ); + return; + } + + if ( fmin < 0. ) + { + plwarn( "plgradient_soft: fmin < 0. set to 0." ); + fmin = 0.; + } + if ( fmax > 1. ) + { + plwarn( "plgradient_soft: fmax > 1. set to 1." ); + fmax = 1.; + } + if ( fmin > fmax ) + { + plabort( "plgradient_soft: fmin > fmax" ); + return; + } + + /* Define polygon boundary so it is accessible from gradient_defined. */ + plsc->n_polygon = n; + plsc->x_polygon = x; + plsc->y_polygon = y; + + /* Find x and y range of polygon. */ + xmin = x[0]; + xmax = xmin; + ymin = y[0]; + ymax = ymin; + /* Also find x range in rotated coordinate system where + * xrot = x*cosangle + y*sinangle. */ + cosangle = cos( PI / 180. * angle ); + sinangle = sin( PI / 180. * angle ); + xrot = x[0] * cosangle + y[0] * sinangle; + xrot_min = xrot; + xrot_max = xrot; + for ( i = 1; i < n; i++ ) + { + if ( x[i] < xmin ) + xmin = x[i]; + else if ( x[i] > xmax ) + xmax = x[i]; + + if ( y[i] < ymin ) + ymin = y[i]; + else if ( y[i] > ymax ) + ymax = y[i]; + + xrot = x[i] * cosangle + y[i] * sinangle; + if ( xrot < xrot_min ) + xrot_min = xrot; + else if ( xrot > xrot_max ) + xrot_max = xrot; + } + + /* 2 x 2 array more than sufficient to define plane. */ + plAlloc2dGrid( &z, 2, 2 ); + xrot = xmin * cosangle + ymin * sinangle; + z[0][0] = (( xrot - xrot_min ) * fmin + ( xrot_max - xrot ) * fmax ) / + ( xrot_max - xrot_min ); + xrot = xmax * cosangle + ymin * sinangle; + z[1][0] = (( xrot - xrot_min ) * fmin + ( xrot_max - xrot ) * fmax ) / + ( xrot_max - xrot_min ); + xrot = xmin * cosangle + ymax * sinangle; + z[0][1] = (( xrot - xrot_min ) * fmin + ( xrot_max - xrot ) * fmax ) / + ( xrot_max - xrot_min ); + xrot = xmax * cosangle + ymax * sinangle; + z[1][1] = (( xrot - xrot_min ) * fmin + ( xrot_max - xrot ) * fmax ) / + ( xrot_max - xrot_min ); + + /* 101 edges gives reasonably smooth results for example 30. */ + #define NEDGE 101 + /* Define NEDGE shade edges (or NEDGE-1 shade levels) + * from fmin to fmax. */ + if (( edge = (PLFLT *) malloc( NEDGE * sizeof ( PLFLT ))) == NULL ) + plexit( "plgradient_soft: Insufficient memory" ); + for ( i = 0; i < NEDGE; i++ ) + edge[i] = fmin + ( fmax - fmin ) * (PLFLT) i / (PLFLT) ( NEDGE - 1 ); + + /* For some reason, gradient_defined doesn't work correctly yet so use NULL + * until this issue is sorted out. + * plshades( z, 2, 2, gradient_defined, xmin, xmax, ymin, ymax, + * edge, NEDGE, 0, -1, 2, plfill, 0, NULL, NULL ); */ + plshades( z, 2, 2, NULL, xmin, xmax, ymin, ymax, + edge, NEDGE, 0, -1, 2, plfill, 0, NULL, NULL ); + free((void *) edge ); + plFree2dGrid( z, 2, 2 ); +} + +PLINT +gradient_defined( PLFLT x, PLFLT y ) +{ + return PLP_pointinpolygon( plsc->n_polygon, plsc->x_polygon, plsc->y_polygon, + x, y ); +} Property changes on: trunk/src/plgradient.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/src/plline.c =================================================================== --- trunk/src/plline.c 2009-11-26 22:53:23 UTC (rev 10629) +++ trunk/src/plline.c 2009-11-27 01:53:55 UTC (rev 10630) @@ -1435,20 +1435,20 @@ static int pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ) { - int i, return_value; + int i, return_value; PLFLT *xflt, *yflt; - if(( xflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) + if (( xflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) { plexit( "pointinpolygon: Insufficient memory" ); } - if(( yflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) + if (( yflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) { plexit( "pointinpolygon: Insufficient memory" ); } for ( i = 0; i < n; i++ ) { - xflt[i] = (PLFLT) x[i]; - yflt[i] = (PLFLT) y[i]; + xflt[i] = (PLFLT) x[i]; + yflt[i] = (PLFLT) y[i]; } return_value = PLP_pointinpolygon( n, xflt, yflt, (PLFLT) xp, (PLFLT) yp ); free( xflt ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-11-29 07:47:15
|
Revision: 10643 http://plplot.svn.sourceforge.net/plplot/?rev=10643&view=rev Author: airwin Date: 2009-11-29 07:47:06 +0000 (Sun, 29 Nov 2009) Log Message: ----------- Implement PLESC_GRADIENT infrastructure to allow drivers to render the gradient rather than using the fallback method. No drivers actually implement this yet. Modified Paths: -------------- trunk/include/plcore.h trunk/include/plplot.h trunk/include/plplotP.h trunk/include/plstrm.h trunk/src/plcore.c trunk/src/plgradient.c Modified: trunk/include/plcore.h =================================================================== --- trunk/include/plcore.h 2009-11-29 07:44:30 UTC (rev 10642) +++ trunk/include/plcore.h 2009-11-29 07:47:06 UTC (rev 10643) @@ -54,6 +54,7 @@ static void grline( short *, short *, PLINT ); static void grpolyline( short *, short *, PLINT ); static void grfill( short *, short *, PLINT ); +static void grgradient( short *, short *, PLINT ); static void plSelectDev( void ); static void pldi_ini( void ); static void calc_diplt( void ); Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2009-11-29 07:44:30 UTC (rev 10642) +++ trunk/include/plplot.h 2009-11-29 07:47:06 UTC (rev 10643) @@ -236,6 +236,7 @@ #define PLESC_START_RASTERIZE 32 /* start rasterized rendering */ #define PLESC_END_RASTERIZE 33 /* end rasterized rendering */ #define PLESC_ARC 34 /* render an arc */ +#define PLESC_GRADIENT 35 /* render a gradient */ /* Alternative unicode text handling control characters */ #define PLTEXT_FONTCHANGE 0 /* font change in the text stream */ Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-11-29 07:44:30 UTC (rev 10642) +++ trunk/include/plplotP.h 2009-11-29 07:47:06 UTC (rev 10643) @@ -942,6 +942,11 @@ void plP_fill( short *x, short *y, PLINT npts ); +/* Render gradient */ + +void +plP_gradient( short *x, short *y, PLINT npts ); + /* draw image */ void Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2009-11-29 07:44:30 UTC (rev 10642) +++ trunk/include/plstrm.h 2009-11-29 07:47:06 UTC (rev 10643) @@ -155,6 +155,7 @@ * plbuf_read PLINT Set during a plot buffer redraw * plbuf_write PLINT Set if driver needs to use the plot buffer * dev_fill0 PLINT Set if driver can do solid area fills + * dev_gradient PLINT Set if driver can do (linear) gradients * dev_text PLINT Set if driver want to do it's only text drawing * dev_unicode PLINT Set if driver wants unicode * dev_hrshsym PLINT Set for Hershey symbols to be used @@ -491,7 +492,8 @@ * **************************************************************************** * - * Gradient variables. + * Variables used in plgradient software fallback to communicate the polygon + * to the gradient_define callback used by plshades. * * n_polygon Number of vertex points in the polygon defining the * boundary of the gradient. @@ -499,6 +501,11 @@ * defining the boundary of the gradient. * y_polygon Pointer to array of y vertex points in the polygon * defining the boundary of the gradient. + **************************************************************************** + * + * Variables used to store gradient information for device drivers. + * + * gradient_angle Angle (radians) of gradient from horizontal axis. \*--------------------------------------------------------------------------*/ #define PL_MAX_CMAP1CP 256 @@ -742,6 +749,9 @@ QSASConfig *qsasconfig; + /* Gradient section. */ + PLINT dev_gradient; + PLFLT gradient_angle; /* The next three variables define the polygon boundary used * in the software fallback for the gradient. */ PLINT n_polygon; Modified: trunk/src/plcore.c =================================================================== --- trunk/src/plcore.c 2009-11-29 07:44:30 UTC (rev 10642) +++ trunk/src/plcore.c 2009-11-29 07:47:06 UTC (rev 10643) @@ -462,6 +462,44 @@ } } +/* Render a gradient */ +/* The plot buffer must be called first */ +/* N.B. plP_gradient is never called (see plgradient) unless the + * device driver has set plsc->dev_gradient to true. */ + +void +plP_gradient( short *x, short *y, PLINT npts ) +{ + PLINT i, clpxmi, clpxma, clpymi, clpyma; + + plsc->page_status = DRAWING; + + if ( plsc->plbuf_write ) + { + plsc->dev_npts = npts; + plsc->dev_x = x; + plsc->dev_y = y; + plbuf_esc( plsc, PLESC_GRADIENT, NULL ); + } + + /* Render gradient with driver. */ + if ( plsc->difilt ) + { + for ( i = 0; i < npts; i++ ) + { + xscl[i] = x[i]; + yscl[i] = y[i]; + } + difilt( xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma ); + plP_plfclp( xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma, + grgradient ); + } + else + { + grgradient( x, y, npts ); + } +} + /* Account for driver ability to draw text itself */ /* #define DEBUG_TEXT @@ -1150,6 +1188,20 @@ plrestore_locale( save_locale ); } +static void +grgradient( short *x, short *y, PLINT npts ) +{ + char * save_locale; + plsc->dev_npts = npts; + plsc->dev_x = x; + plsc->dev_y = y; + + save_locale = plsave_set_locale(); + ( *plsc->dispatch_table->pl_esc )((struct PLStream_struct *) plsc, + PLESC_GRADIENT, NULL ); + plrestore_locale( save_locale ); +} + /*--------------------------------------------------------------------------*\ * void difilt * Modified: trunk/src/plgradient.c =================================================================== --- trunk/src/plgradient.c 2009-11-29 07:44:30 UTC (rev 10642) +++ trunk/src/plgradient.c 2009-11-29 07:47:06 UTC (rev 10643) @@ -61,12 +61,34 @@ return; } - /* For now this is the only method, but once at least one device driver - * implements a native linear gradient for a device, this will become - * the software fallback method for devices that don't have - * native linear gradient capability. */ - plgradient_soft( n, x, y, angle ); -} + if(!plsc->dev_gradient) + { + plgradient_soft( n, x, y, angle ); + } + else + { + plsc->gradient_angle = PI * angle/180.; + PLINT i, xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY]; + if ( n > PL_MAXPOLY - 1 ) + { + plwarn( "plgradient: too many points in polygon" ); + n = PL_MAXPOLY; + } + for ( i = 0; i < n; i++ ) + { + xpoly[i] = plP_wcpcx( x[i] ); + ypoly[i] = plP_wcpcy( y[i] ); + } + if ( x[0] != x[n - 1] || y[0] != y[n - 1] ) + { + if ( n < PL_MAXPOLY ) n++; + xpoly[n - 1] = plP_wcpcx( x[0] ); + ypoly[n - 1] = plP_wcpcy( y[0] ); + } + plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma, + plsc->clpymi, plsc->clpyma, plP_gradient ); + } + } /*----------------------------------------------------------------------*\ * void plgradient_soft() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-11-29 20:02:58
|
Revision: 10648 http://plplot.svn.sourceforge.net/plplot/?rev=10648&view=rev Author: airwin Date: 2009-11-29 20:02:50 +0000 (Sun, 29 Nov 2009) Log Message: ----------- Style recent changes. Modified Paths: -------------- trunk/include/plplot.h trunk/include/plstrm.h trunk/src/plcore.c trunk/src/plgradient.c trunk/src/plgset.c trunk/src/plshade.c Modified: trunk/include/plplot.h =================================================================== --- trunk/include/plplot.h 2009-11-29 20:00:47 UTC (rev 10647) +++ trunk/include/plplot.h 2009-11-29 20:02:50 UTC (rev 10648) @@ -480,7 +480,7 @@ */ enum PLAttributeName // alphabetical? -{ +{ PL_CMAP0, PL_CMAP1, PL_CURCHARSIZE, Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2009-11-29 20:00:47 UTC (rev 10647) +++ trunk/include/plstrm.h 2009-11-29 20:02:50 UTC (rev 10648) @@ -750,13 +750,13 @@ QSASConfig *qsasconfig; /* Gradient section. */ - PLINT dev_gradient; - PLFLT gradient_angle; + PLINT dev_gradient; + PLFLT gradient_angle; /* The next three variables define the polygon boundary used * in the software fallback for the gradient. */ - PLINT n_polygon; - PLFLT *x_polygon; - PLFLT *y_polygon; + PLINT n_polygon; + PLFLT *x_polygon; + PLFLT *y_polygon; } PLStream; /*--------------------------------------------------------------------------*\ Modified: trunk/src/plcore.c =================================================================== --- trunk/src/plcore.c 2009-11-29 20:00:47 UTC (rev 10647) +++ trunk/src/plcore.c 2009-11-29 20:02:50 UTC (rev 10648) @@ -485,18 +485,18 @@ /* Render gradient with driver. */ if ( plsc->difilt ) { - for ( i = 0; i < npts; i++ ) - { - xscl[i] = x[i]; - yscl[i] = y[i]; - } - difilt( xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma ); - plP_plfclp( xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma, - grgradient ); + for ( i = 0; i < npts; i++ ) + { + xscl[i] = x[i]; + yscl[i] = y[i]; + } + difilt( xscl, yscl, npts, &clpxmi, &clpxma, &clpymi, &clpyma ); + plP_plfclp( xscl, yscl, npts, clpxmi, clpxma, clpymi, clpyma, + grgradient ); } else { - grgradient( x, y, npts ); + grgradient( x, y, npts ); } } Modified: trunk/src/plgradient.c =================================================================== --- trunk/src/plgradient.c 2009-11-29 20:00:47 UTC (rev 10647) +++ trunk/src/plgradient.c 2009-11-29 20:02:50 UTC (rev 10648) @@ -61,34 +61,34 @@ return; } - if(!plsc->dev_gradient) + if ( !plsc->dev_gradient ) { plgradient_soft( n, x, y, angle ); } else { - plsc->gradient_angle = PI * angle/180.; - PLINT i, xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY]; - if ( n > PL_MAXPOLY - 1 ) - { - plwarn( "plgradient: too many points in polygon" ); - n = PL_MAXPOLY; - } - for ( i = 0; i < n; i++ ) - { - xpoly[i] = plP_wcpcx( x[i] ); - ypoly[i] = plP_wcpcy( y[i] ); - } - if ( x[0] != x[n - 1] || y[0] != y[n - 1] ) - { - if ( n < PL_MAXPOLY ) n++; - xpoly[n - 1] = plP_wcpcx( x[0] ); - ypoly[n - 1] = plP_wcpcy( y[0] ); - } - plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma, - plsc->clpymi, plsc->clpyma, plP_gradient ); + plsc->gradient_angle = PI * angle / 180.; + PLINT i, xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY]; + if ( n > PL_MAXPOLY - 1 ) + { + plwarn( "plgradient: too many points in polygon" ); + n = PL_MAXPOLY; + } + for ( i = 0; i < n; i++ ) + { + xpoly[i] = plP_wcpcx( x[i] ); + ypoly[i] = plP_wcpcy( y[i] ); + } + if ( x[0] != x[n - 1] || y[0] != y[n - 1] ) + { + if ( n < PL_MAXPOLY ) n++; + xpoly[n - 1] = plP_wcpcx( x[0] ); + ypoly[n - 1] = plP_wcpcy( y[0] ); + } + plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma, + plsc->clpymi, plsc->clpyma, plP_gradient ); } - } +} /*----------------------------------------------------------------------*\ * void plgradient_soft() Modified: trunk/src/plgset.c =================================================================== --- trunk/src/plgset.c 2009-11-29 20:00:47 UTC (rev 10647) +++ trunk/src/plgset.c 2009-11-29 20:02:50 UTC (rev 10648) @@ -36,31 +36,33 @@ /* get the entire color map 0 */ case PL_CMAP0: attrValue->attributeType = PL_COLORPTR; - attrValue->colorValues = (PLColor *)malloc(sizeof(PLColor) * plsc->ncol0); - for(i=0;i<plsc->ncol0;i++){ - attrValue->colorValues[i].r = plsc->cmap0[i].r; - attrValue->colorValues[i].g = plsc->cmap0[i].g; - attrValue->colorValues[i].b = plsc->cmap0[i].b; - attrValue->colorValues[i].a = plsc->cmap0[i].a; + attrValue->colorValues = (PLColor *) malloc( sizeof ( PLColor ) * plsc->ncol0 ); + for ( i = 0; i < plsc->ncol0; i++ ) + { + attrValue->colorValues[i].r = plsc->cmap0[i].r; + attrValue->colorValues[i].g = plsc->cmap0[i].g; + attrValue->colorValues[i].b = plsc->cmap0[i].b; + attrValue->colorValues[i].a = plsc->cmap0[i].a; } attrValue->nValues = plsc->ncol0; break; /* get the entire color map 1 */ case PL_CMAP1: attrValue->attributeType = PL_COLORPTR; - attrValue->colorValues = (PLColor *)malloc(sizeof(PLColor) * plsc->ncol1); - for(i=0;i<plsc->ncol1;i++){ - attrValue->colorValues[i].r = plsc->cmap1[i].r; - attrValue->colorValues[i].g = plsc->cmap1[i].g; - attrValue->colorValues[i].b = plsc->cmap1[i].b; - attrValue->colorValues[i].a = plsc->cmap1[i].a; + attrValue->colorValues = (PLColor *) malloc( sizeof ( PLColor ) * plsc->ncol1 ); + for ( i = 0; i < plsc->ncol1; i++ ) + { + attrValue->colorValues[i].r = plsc->cmap1[i].r; + attrValue->colorValues[i].g = plsc->cmap1[i].g; + attrValue->colorValues[i].b = plsc->cmap1[i].b; + attrValue->colorValues[i].a = plsc->cmap1[i].a; } attrValue->nValues = plsc->ncol1; break; /* get the current (scaled) character height */ case PL_CURCHARSIZE: attrValue->attributeType = PL_FLT; - attrValue->fltValue = plsc->chrht; + attrValue->fltValue = plsc->chrht; break; /* get the current color map 0 color */ case PL_CURCOLOR0: @@ -73,27 +75,27 @@ /* get the current (scaled) major tick size */ case PL_CURMAJORTICK: attrValue->attributeType = PL_FLT; - attrValue->fltValue = plsc->majht; + attrValue->fltValue = plsc->majht; break; /* get the current (scaled) minor tick size */ case PL_CURMINORTICK: attrValue->attributeType = PL_FLT; - attrValue->fltValue = plsc->minht; + attrValue->fltValue = plsc->minht; break; /* get the default character height (in mm) */ case PL_DEFCHARSIZE: attrValue->attributeType = PL_FLT; - attrValue->fltValue = plsc->chrdef; + attrValue->fltValue = plsc->chrdef; break; /* get the default major tick size (in mm) */ case PL_DEFMAJORTICK: attrValue->attributeType = PL_FLT; - attrValue->fltValue = plsc->majdef; + attrValue->fltValue = plsc->majdef; break; /* get the default minor tick size (in mm) */ case PL_DEFMINORTICK: attrValue->attributeType = PL_FLT; - attrValue->fltValue = plsc->mindef; + attrValue->fltValue = plsc->mindef; break; /* get the index of the current color map 0 color */ case PL_ICOL0: @@ -103,7 +105,7 @@ /* get the index of the current color map 1 color */ case PL_ICOL1: attrValue->attributeType = PL_FLT; - attrValue->intValue = ((PLFLT) plsc->icol1) / ((PLFLT) plsc->ncol1); + attrValue->intValue = ((PLFLT) plsc->icol1 ) / ((PLFLT) plsc->ncol1 ); break; /* get the number of colors in color map 0 */ case PL_NCOL0: @@ -125,37 +127,37 @@ attrValue->attributeType = PL_INT; attrValue->intValue = plsc->precis; break; - /* get whether or not to use user specified number of digits of precision */ + /* get whether or not to use user specified number of digits of precision */ case PL_SETPRECISION: attrValue->attributeType = PL_INT; attrValue->intValue = plsc->setpre; break; - /* get x fields digit value (?) */ + /* get x fields digit value (?) */ case PL_XDIGITS: attrValue->attributeType = PL_INT; attrValue->intValue = plsc->xdigits; break; - /* get x maximum digits (0 = no maximum) */ + /* get x maximum digits (0 = no maximum) */ case PL_XDIGMAX: attrValue->attributeType = PL_INT; attrValue->intValue = plsc->xdigmax; break; - /* get y fields digit value (?) */ + /* get y fields digit value (?) */ case PL_YDIGITS: attrValue->attributeType = PL_INT; attrValue->intValue = plsc->ydigits; break; - /* get y maximum digits (0 = no maximum) */ + /* get y maximum digits (0 = no maximum) */ case PL_YDIGMAX: attrValue->attributeType = PL_INT; attrValue->intValue = plsc->ydigmax; break; - /* get z fields digit value (?) */ + /* get z fields digit value (?) */ case PL_ZDIGITS: attrValue->attributeType = PL_INT; attrValue->intValue = plsc->zdigits; break; - /* get z maximum digits (0 = no maximum) */ + /* get z maximum digits (0 = no maximum) */ case PL_ZDIGMAX: attrValue->attributeType = PL_INT; attrValue->intValue = plsc->zdigmax; @@ -179,132 +181,134 @@ PLINT i; PLINT *r, *g, *b; PLFLT *a; - + switch ( attrName ) { /* set color map 0 from an array of PL_COLOR values */ case PL_CMAP0: if ( attrValue.attributeType == PL_COLORPTR ) { - r = (PLINT *) malloc (sizeof(PLINT) * attrValue.nValues); - g = (PLINT *) malloc (sizeof(PLINT) * attrValue.nValues); - b = (PLINT *) malloc (sizeof(PLINT) * attrValue.nValues); - a = (PLFLT *) malloc (sizeof(PLFLT) * attrValue.nValues); - for(i=0;i<attrValue.nValues;i++){ - r[i] = attrValue.colorValues[i].r; - g[i] = attrValue.colorValues[i].g; - b[i] = attrValue.colorValues[i].b; + r = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); + g = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); + b = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); + a = (PLFLT *) malloc( sizeof ( PLFLT ) * attrValue.nValues ); + for ( i = 0; i < attrValue.nValues; i++ ) + { + r[i] = attrValue.colorValues[i].r; + g[i] = attrValue.colorValues[i].g; + b[i] = attrValue.colorValues[i].b; a[i] = attrValue.colorValues[i].a; - } - plscmap0a(r, g, b, a, attrValue.nValues); - free(r); - free(g); - free(b); - free(a); + } + plscmap0a( r, g, b, a, attrValue.nValues ); + free( r ); + free( g ); + free( b ); + free( a ); } break; /* set color map 1 from an array of PL_COLOR values */ case PL_CMAP1: if ( attrValue.attributeType == PL_COLORPTR ) { - r = (PLINT *) malloc (sizeof(PLINT) * attrValue.nValues); - g = (PLINT *) malloc (sizeof(PLINT) * attrValue.nValues); - b = (PLINT *) malloc (sizeof(PLINT) * attrValue.nValues); - a = (PLFLT *) malloc (sizeof(PLFLT) * attrValue.nValues); - for(i=0;i<attrValue.nValues;i++){ - r[i] = attrValue.colorValues[i].r; - g[i] = attrValue.colorValues[i].g; - b[i] = attrValue.colorValues[i].b; + r = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); + g = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); + b = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); + a = (PLFLT *) malloc( sizeof ( PLFLT ) * attrValue.nValues ); + for ( i = 0; i < attrValue.nValues; i++ ) + { + r[i] = attrValue.colorValues[i].r; + g[i] = attrValue.colorValues[i].g; + b[i] = attrValue.colorValues[i].b; a[i] = attrValue.colorValues[i].a; - } - plscmap1a(r, g, b, a, attrValue.nValues); - free(r); - free(g); - free(b); - free(a); + } + plscmap1a( r, g, b, a, attrValue.nValues ); + free( r ); + free( g ); + free( b ); + free( a ); } break; - /* set the (scaled) character height */ + /* set the (scaled) character height */ case PL_CURCHARSIZE: if ( attrValue.attributeType == PL_FLT ) - { - plschr(0.0, attrValue.fltValue); - } + { + plschr( 0.0, attrValue.fltValue ); + } break; /* set the current color map 0 color */ case PL_CURCOLOR0: if ( attrValue.attributeType == PL_COLOR ) { plscol0( plsc->icol0, - attrValue.colorValue.r, - attrValue.colorValue.g, - attrValue.colorValue.b ); + attrValue.colorValue.r, + attrValue.colorValue.g, + attrValue.colorValue.b ); plcol0( plsc->icol0 ); } break; /* set the (scaled) major tick length */ case PL_CURMAJORTICK: if ( attrValue.attributeType == PL_FLT ) - { - plsmaj( 0.0, attrValue.fltValue); - } + { + plsmaj( 0.0, attrValue.fltValue ); + } break; /* set the (scaled) minor tick length */ case PL_CURMINORTICK: if ( attrValue.attributeType == PL_FLT ) - { - plsmin( 0.0, attrValue.fltValue); - } + { + plsmin( 0.0, attrValue.fltValue ); + } break; /* set the default character height (mm) */ case PL_DEFCHARSIZE: if ( attrValue.attributeType == PL_FLT ) - { - plschr( attrValue.fltValue, plsc->chrht); - } + { + plschr( attrValue.fltValue, plsc->chrht ); + } break; /* set the default major tick size (mm) */ case PL_DEFMAJORTICK: if ( attrValue.attributeType == PL_FLT ) - { - plsmaj( attrValue.fltValue, plsc->majht); - } + { + plsmaj( attrValue.fltValue, plsc->majht ); + } break; /* set the default minor tick size (mm) */ case PL_DEFMINORTICK: if ( attrValue.attributeType == PL_FLT ) - { - plsmin( attrValue.fltValue, plsc->minht); - } + { + plsmin( attrValue.fltValue, plsc->minht ); + } break; /* set the index of the current color map 0 color */ case PL_ICOL0: if ( attrValue.attributeType == PL_INT ) - { - plcol0( attrValue.intValue ); + { + plcol0( attrValue.intValue ); } - break; + break; /* set the index of the current color map 1 color */ case PL_ICOL1: if ( attrValue.attributeType == PL_FLT ) - { - plcol1( attrValue.fltValue ); + { + plcol1( attrValue.fltValue ); } - break; + break; /* set the number of colors in color map 0 */ case PL_NCOL0: if ( attrValue.attributeType == PL_INT ) - { - plscmap0n( attrValue.intValue ); + { + plscmap0n( attrValue.intValue ); } - break; + break; /* set the number of colors in color map 1 */ case PL_NCOL1: if ( attrValue.attributeType == PL_INT ) - { - plscmap1n( attrValue.intValue ); + { + plscmap1n( attrValue.intValue ); } - break; + break; /* set the current pen width */ case PL_PENWIDTH: if ( attrValue.attributeType == PL_INT ) @@ -316,56 +320,56 @@ case PL_PRECISION: if ( attrValue.attributeType == PL_INT ) { - plprec( plsc->setpre, attrValue.intValue ); + plprec( plsc->setpre, attrValue.intValue ); } break; /* set whether or not to use user specified number of digits of precision */ case PL_SETPRECISION: if ( attrValue.attributeType == PL_INT ) { - plprec( attrValue.intValue, plsc->precis ); + plprec( attrValue.intValue, plsc->precis ); } break; - /* set x fields digit value (?) */ + /* set x fields digit value (?) */ case PL_XDIGITS: if ( attrValue.attributeType == PL_INT ) { - plsxax( plsc->xdigmax, attrValue.intValue ); + plsxax( plsc->xdigmax, attrValue.intValue ); } break; - /* get x maximum digits (0 = no maximum) */ + /* get x maximum digits (0 = no maximum) */ case PL_XDIGMAX: if ( attrValue.attributeType == PL_INT ) { - plsxax( attrValue.intValue, plsc->xdigits ); + plsxax( attrValue.intValue, plsc->xdigits ); } break; - /* set y fields digit value (?) */ + /* set y fields digit value (?) */ case PL_YDIGITS: if ( attrValue.attributeType == PL_INT ) { - plsyax( plsc->ydigmax, attrValue.intValue ); + plsyax( plsc->ydigmax, attrValue.intValue ); } break; - /* set y maximum digits (0 = no maximum) */ + /* set y maximum digits (0 = no maximum) */ case PL_YDIGMAX: if ( attrValue.attributeType == PL_INT ) { - plsyax( attrValue.intValue, plsc->ydigits ); + plsyax( attrValue.intValue, plsc->ydigits ); } break; - /* set z fields digit value (?) */ + /* set z fields digit value (?) */ case PL_ZDIGITS: if ( attrValue.attributeType == PL_INT ) { - plszax( plsc->zdigmax, attrValue.intValue ); + plszax( plsc->zdigmax, attrValue.intValue ); } break; - /* set z maximum digits (0 = no maximum) */ + /* set z maximum digits (0 = no maximum) */ case PL_ZDIGMAX: if ( attrValue.attributeType == PL_INT ) { - plszax( attrValue.intValue, plsc->zdigits ); + plszax( attrValue.intValue, plsc->zdigits ); } break; default: Modified: trunk/src/plshade.c =================================================================== --- trunk/src/plshade.c 2009-11-29 20:00:47 UTC (rev 10647) +++ trunk/src/plshade.c 2009-11-29 20:02:50 UTC (rev 10648) @@ -124,15 +124,15 @@ #include "plplotP.h" #include <float.h> -#define MISSING_MIN_DEF (PLFLT) 1.0 -#define MISSING_MAX_DEF (PLFLT) -1.0 +#define MISSING_MIN_DEF (PLFLT) 1.0 +#define MISSING_MAX_DEF (PLFLT) -1.0 -#define NEG 1 -#define POS 8 -#define OK 0 -#define UNDEF 64 -#define NUMBER_BISECTIONS 10 +#define NEG 1 +#define POS 8 +#define OK 0 +#define UNDEF 64 +#define NUMBER_BISECTIONS 10 #define linear( val1, val2, level ) (( level - val1 ) / ( val2 - val1 )) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-11-30 06:46:06
|
Revision: 10649 http://plplot.svn.sourceforge.net/plplot/?rev=10649&view=rev Author: airwin Date: 2009-11-30 06:45:59 +0000 (Mon, 30 Nov 2009) Log Message: ----------- Use end-point coordinates (which allows correct coordinate transformations) rather than angle to define the gradient. There still appears to be some subtle misunderstanding on my part of how the SVG protocol interprets the end-point coordinates of the gradient, however, since the -dev svg results for the gradient are still incorrect. Modified Paths: -------------- trunk/drivers/svg.c trunk/include/plstrm.h trunk/src/plgradient.c Modified: trunk/drivers/svg.c =================================================================== --- trunk/drivers/svg.c 2009-11-29 20:02:50 UTC (rev 10648) +++ trunk/drivers/svg.c 2009-11-30 06:45:59 UTC (rev 10649) @@ -98,7 +98,7 @@ /* General */ static void poly_line( PLStream *, short *, short *, PLINT, short ); -static void gradient( PLStream *, short *, short *, PLINT, PLFLT ); +static void gradient( PLStream *, short *, short *, PLINT ); static void write_hex( FILE *, unsigned char ); static void write_unicode( FILE *, PLUNICODE ); static void specify_font( FILE *, PLUNICODE ); @@ -395,8 +395,7 @@ poly_line( pls, pls->dev_x, pls->dev_y, pls->dev_npts, 1 ); break; case PLESC_GRADIENT: /* render gradient inside polygon */ - gradient( pls, pls->dev_x, pls->dev_y, pls->dev_npts, - pls->gradient_angle ); + gradient( pls, pls->dev_x, pls->dev_y, pls->dev_npts ); break; case PLESC_HAS_TEXT: /* render text */ proc_str( pls, (EscText *) ptr ); @@ -469,51 +468,13 @@ * Draws gradient * ---------------------------------------------------------------------*/ -void gradient( PLStream *pls, short *xa, short *ya, PLINT npts, PLFLT angle ) +void gradient( PLStream *pls, short *xa, short *ya, PLINT npts ) { - int i, irot_min, irot_max; - PLFLT xrot, xrot_min, xrot_max, x1, y1, x2, y2; + int i; /* 27 should be the maximum needed below, but be generous.*/ - char buffer[50]; - SVG *aStream; + char buffer[50]; + SVG *aStream; - /* Find (x1, y1) and (x2, y2) corresponding to beginning and end - * of gradient vector. */ - double cosangle = cos( angle ); - double sinangle = sin( angle ); - /* gradient polygon must have at least two points, and this test also - * avoids accessing undefined variables. */ - if ( npts < 2 ) - return; - xrot = xa[0] * cosangle + ya[0] * sinangle; - xrot_min = xrot; - xrot_max = xrot; - irot_min = 0; - irot_max = 0; - for ( i = 1; i < npts; i++ ) - { - xrot = xa[i] * cosangle + ya[i] * sinangle; - if ( xrot < xrot_min ) - { - xrot_min = xrot; - irot_min = i; - } - else if ( xrot > xrot_max ) - { - xrot_max = xrot; - irot_max = i; - } - } - /* xrot_min and xrot_max are the minimum and maximum rotated x coordinate - * of polygon vertices. Use the vertex corresponding to the minimum - * as the (x1, y1) base of the gradient vector, and calculate the - * (x2, y2) tip of the gradient vector from the range in rotated - * x coordinate and the angle of the gradient. */ - x1 = xa[irot_min]; - y1 = ya[irot_min]; - x2 = x1 + ( xrot_max - xrot_min ) * cosangle; - y2 = y1 + ( xrot_max - xrot_min ) * sinangle; - aStream = pls->dev; svg_open( aStream, "g>" ); @@ -523,13 +484,13 @@ sprintf( buffer, "MyGradient%010d", aStream->gradient_index ); svg_attr_value( aStream, "id", buffer ); svg_attr_value( aStream, "gradientUnits", "userSpaceOnUse" ); - sprintf( buffer, "%.2f", x1 / aStream->scale ); + sprintf( buffer, "%.2f", pls->xgradient[0] / aStream->scale ); svg_attr_value( aStream, "x1", buffer ); - sprintf( buffer, "%.2f", y1 / aStream->scale ); + sprintf( buffer, "%.2f", pls->ygradient[0] / aStream->scale ); svg_attr_value( aStream, "y1", buffer ); - sprintf( buffer, "%.2f", x2 / aStream->scale ); + sprintf( buffer, "%.2f", pls->xgradient[1] / aStream->scale ); svg_attr_value( aStream, "x2", buffer ); - sprintf( buffer, "%.2f", y2 / aStream->scale ); + sprintf( buffer, "%.2f", pls->ygradient[1] / aStream->scale ); svg_attr_value( aStream, "y2", buffer ); svg_general( aStream, ">\n" ); Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2009-11-29 20:02:50 UTC (rev 10648) +++ trunk/include/plstrm.h 2009-11-30 06:45:59 UTC (rev 10649) @@ -505,7 +505,9 @@ * * Variables used to store gradient information for device drivers. * - * gradient_angle Angle (radians) of gradient from horizontal axis. + * xgradient Pointer to array of x coordinates of gradient vector. + * ygradient Pointer to array of y coordinates of gradient vector. + * ngradient Number of points (two) in gradient vector. \*--------------------------------------------------------------------------*/ #define PL_MAX_CMAP1CP 256 @@ -751,12 +753,12 @@ /* Gradient section. */ PLINT dev_gradient; - PLFLT gradient_angle; + PLINT ngradient; + PLINT *xgradient, *ygradient; /* The next three variables define the polygon boundary used * in the software fallback for the gradient. */ PLINT n_polygon; - PLFLT *x_polygon; - PLFLT *y_polygon; + PLFLT *x_polygon, *y_polygon; } PLStream; /*--------------------------------------------------------------------------*\ Modified: trunk/src/plgradient.c =================================================================== --- trunk/src/plgradient.c 2009-11-29 20:02:50 UTC (rev 10648) +++ trunk/src/plgradient.c 2009-11-30 06:45:59 UTC (rev 10649) @@ -67,8 +67,57 @@ } else { - plsc->gradient_angle = PI * angle / 180.; - PLINT i, xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY]; + #define NGRAD 2 + int i, irot_min, irot_max; + PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY]; + PLINT xgrad[NGRAD], ygrad[NGRAD], clpxmi, clpxma, clpymi, clpyma; + PLFLT dxgrad[NGRAD], dygrad[NGRAD], xrot, xrot_min, xrot_max; + + /* Find (x1, y1) and (x2, y2) corresponding to beginning and end + * of gradient vector. */ + double cosangle = cos( PI * angle / 180. ); + double sinangle = sin( PI * angle / 180. ); + xrot = x[0] * cosangle + y[0] * sinangle; + xrot_min = xrot; + xrot_max = xrot; + irot_min = 0; + irot_max = 0; + for ( i = 1; i < n; i++ ) + { + xrot = x[i] * cosangle + y[i] * sinangle; + if ( xrot < xrot_min ) + { + xrot_min = xrot; + irot_min = i; + } + else if ( xrot > xrot_max ) + { + xrot_max = xrot; + irot_max = i; + } + } + /* xrot_min and xrot_max are the minimum and maximum rotated x + * coordinate of polygon vertices. Use the vertex corresponding + * to the minimum as the (xgrad[0], ygrad[0]) base of the + * gradient vector, and calculate the (xgrad[1], ygrad[1]) tip of + * the gradient vector from the range in rotated x coordinate and + * the angle of the gradient. */ + dxgrad[0] = x[irot_min]; + dxgrad[1] = dxgrad[0] + ( xrot_max - xrot_min ) * cosangle; + dygrad[0] = y[irot_min]; + dygrad[1] = dygrad[0] + ( xrot_max - xrot_min ) * sinangle; + for ( i = 0; i < NGRAD; i++ ) + { + xgrad[i] = plP_wcpcx( dxgrad[i] ); + ygrad[i] = plP_wcpcy( dygrad[i] ); + } + if ( plsc->difilt ) + difilt( xgrad, ygrad, NGRAD, &clpxmi, &clpxma, &clpymi, &clpyma ); + plsc->xgradient = xgrad; + plsc->ygradient = ygrad; + plsc->ngradient = NGRAD; + + if ( n > PL_MAXPOLY - 1 ) { plwarn( "plgradient: too many points in polygon" ); @@ -87,6 +136,9 @@ } plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma, plsc->clpymi, plsc->clpyma, plP_gradient ); + /* Plot line corresponding to gradient to give visual + * debugging cue. */ + plline( NGRAD, dxgrad, dygrad ); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-11-30 17:57:39
|
Revision: 10651 http://plplot.svn.sourceforge.net/plplot/?rev=10651&view=rev Author: airwin Date: 2009-11-30 17:57:25 +0000 (Mon, 30 Nov 2009) Log Message: ----------- Move plP_plfclp and associated routines from plline.c to its more natural position in plfill.c Modified Paths: -------------- trunk/include/plplotP.h trunk/src/plfill.c trunk/src/plline.c Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-11-30 12:05:36 UTC (rev 10650) +++ trunk/include/plplotP.h 2009-11-30 17:57:25 UTC (rev 10651) @@ -468,6 +468,12 @@ int plP_clip_poly( int Ni, PLFLT *Vi[3], int axis, PLFLT dir, PLFLT offset ); +/* Get clipped endpoints */ + +int +plP_clipline( PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2, + PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax ); + /* Stores hex digit value into FCI (font characterization integer). */ void plP_hex2fci( unsigned char hexdigit, unsigned char hexpower, PLUNICODE *pfci ); Modified: trunk/src/plfill.c =================================================================== --- trunk/src/plfill.c 2009-11-30 12:05:36 UTC (rev 10650) +++ trunk/src/plfill.c 2009-11-30 17:57:25 UTC (rev 10651) @@ -24,6 +24,8 @@ #include "plplotP.h" +#define INSIDE( ix, iy ) ( BETW( ix, xmin, xmax ) && BETW( iy, ymin, ymax )) + #define DTOR 0.0174533 #define BINC 50 @@ -36,11 +38,25 @@ /* Static function prototypes */ /* INDENT OFF */ -static int compar( const void *, const void * ); -static void addcoord( PLINT, PLINT ); -static void tran( PLINT *, PLINT *, PLFLT, PLFLT ); -static void buildlist( PLINT, PLINT, PLINT, PLINT, PLINT, PLINT, PLINT ); +static int +compar( const void *, const void * ); +static void +addcoord( PLINT, PLINT ); + +static void +tran( PLINT *, PLINT *, PLFLT, PLFLT ); + +static void +buildlist( PLINT, PLINT, PLINT, PLINT, PLINT, PLINT, PLINT ); + +static int +pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ); + +static int +circulation( PLINT *x, PLINT *y, PLINT npts ); + + /* INDENT ON */ /*----------------------------------------------------------------------*\ @@ -382,3 +398,649 @@ return 0; } + +/*----------------------------------------------------------------------*\ + * void plP_plfclp() + * + * Fills a polygon within the clip limits. + \*----------------------------------------------------------------------*/ + +void +plP_plfclp( PLINT *x, PLINT *y, PLINT npts, + PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax, + void ( *draw )( short *, short *, PLINT )) +{ + PLINT i, x1, x2, y1, y2; + int iclp = 0, iout = 2; + short _xclp[2 * PL_MAXPOLY + 2], _yclp[2 * PL_MAXPOLY + 2]; + short *xclp, *yclp; + int drawable; + int crossed_xmin1 = 0, crossed_xmax1 = 0; + int crossed_ymin1 = 0, crossed_ymax1 = 0; + int crossed_xmin2 = 0, crossed_xmax2 = 0; + int crossed_ymin2 = 0, crossed_ymax2 = 0; + int crossed_up = 0, crossed_down = 0; + int crossed_left = 0, crossed_right = 0; + int inside_lb; + int inside_lu; + int inside_rb; + int inside_ru; + +/* Must have at least 3 points and draw() specified */ + if ( npts < 3 || !draw ) return; + + if ( npts < PL_MAXPOLY ) + { + xclp = _xclp; + yclp = _yclp; + } + else + { + if ((( xclp = (short *) malloc(( 2 * npts + 2 ) * sizeof ( short ))) == NULL ) || + (( yclp = (short *) malloc(( 2 * npts + 2 ) * sizeof ( short ))) == NULL )) + { + plexit( "plP_plfclp: Insufficient memory" ); + } + } + + inside_lb = pointinpolygon( npts, x, y, xmin, ymin ); + inside_lu = pointinpolygon( npts, x, y, xmin, ymax ); + inside_rb = pointinpolygon( npts, x, y, xmax, ymin ); + inside_ru = pointinpolygon( npts, x, y, xmax, ymax ); + + for ( i = 0; i < npts - 1; i++ ) + { + x1 = x[i]; x2 = x[i + 1]; + y1 = y[i]; y2 = y[i + 1]; + + drawable = ( INSIDE( x1, y1 ) && INSIDE( x2, y2 )); + if ( !drawable ) + drawable = !plP_clipline( &x1, &y1, &x2, &y2, + xmin, xmax, ymin, ymax ); + + if ( drawable ) + { + /* Boundary crossing condition -- coming in. */ + crossed_xmin2 = ( x1 == xmin ); crossed_xmax2 = ( x1 == xmax ); + crossed_ymin2 = ( y1 == ymin ); crossed_ymax2 = ( y1 == ymax ); + + crossed_left = ( crossed_left || crossed_xmin2 ); + crossed_right = ( crossed_right || crossed_xmax2 ); + crossed_down = ( crossed_down || crossed_ymin2 ); + crossed_up = ( crossed_up || crossed_ymax2 ); + iout = iclp + 2; + /* If the first segment, just add it. */ + + if ( iclp == 0 ) + { + xclp[iclp] = x1; yclp[iclp] = y1; iclp++; + xclp[iclp] = x2; yclp[iclp] = y2; iclp++; + } + + /* Not first point. If first point of this segment matches up to the + * previous point, just add it. */ + + else if ( x1 == xclp[iclp - 1] && y1 == yclp[iclp - 1] ) + { + xclp[iclp] = x2; yclp[iclp] = y2; iclp++; + } + + /* Otherwise, we need to add both points, to connect the points in the + * polygon along the clip boundary. If we encircled a corner, we have + * to add that first. + */ + + else + { + /* Treat the case where we encircled two corners: + * Construct a polygon out of the subset of vertices + * Note that the direction is important too when adding + * the extra points */ + xclp[iclp + 1] = x2; yclp[iclp + 1] = y2; + xclp[iclp + 2] = x1; yclp[iclp + 2] = y1; + iout = iout - iclp + 1; + /* Upper two */ + if ((( crossed_xmin1 && crossed_xmax2 ) || + ( crossed_xmin2 && crossed_xmax1 )) && + inside_lu ) + { + if ( crossed_xmin1 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + else + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + } + /* Lower two */ + else if ((( crossed_xmin1 && crossed_xmax2 ) || + ( crossed_xmin2 && crossed_xmax1 )) && + inside_lb ) + { + if ( crossed_xmin1 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + else + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + } + /* Left two */ + else if ((( crossed_ymin1 && crossed_ymax2 ) || + ( crossed_ymin2 && crossed_ymax1 )) && + inside_lb ) + { + if ( crossed_ymin1 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + else + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + } + /* Right two */ + else if ((( crossed_ymin1 && crossed_ymax2 ) || + ( crossed_ymin2 && crossed_ymax1 )) && + inside_rb ) + { + if ( crossed_ymin1 ) + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + else + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + } + /* Now the case where we encircled one corner */ + /* Lower left */ + else if (( crossed_xmin1 && crossed_ymin2 ) || + ( crossed_ymin1 && crossed_xmin2 )) + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + /* Lower right */ + else if (( crossed_xmax1 && crossed_ymin2 ) || + ( crossed_ymin1 && crossed_xmax2 )) + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + /* Upper left */ + else if (( crossed_xmin1 && crossed_ymax2 ) || + ( crossed_ymax1 && crossed_xmin2 )) + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + /* Upper right */ + else if (( crossed_xmax1 && crossed_ymax2 ) || + ( crossed_ymax1 && crossed_xmax2 )) + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + + /* Now add current segment. */ + xclp[iclp] = x1; yclp[iclp] = y1; iclp++; + xclp[iclp] = x2; yclp[iclp] = y2; iclp++; + } + + /* Boundary crossing condition -- going out. */ + crossed_xmin1 = ( x2 == xmin ); crossed_xmax1 = ( x2 == xmax ); + crossed_ymin1 = ( y2 == ymin ); crossed_ymax1 = ( y2 == ymax ); + } + } + +/* Limit case - all vertices are outside of bounding box. So just fill entire + * box, *if* the bounding box is completely encircled. + */ + + if ( iclp == 0 ) + { + if ( inside_lb ) + { + xclp[0] = xmin; yclp[0] = ymin; + xclp[1] = xmax; yclp[1] = ymin; + xclp[2] = xmax; yclp[2] = ymax; + xclp[3] = xmin; yclp[3] = ymax; + xclp[4] = xmin; yclp[4] = ymin; + ( *draw )( xclp, yclp, 5 ); + + if ( xclp != _xclp ) + { + free( xclp ); + free( yclp ); + } + + + return; + } + } + +/* Now handle cases where fill polygon intersects two sides of the box */ + + if ( iclp >= 2 ) + { + int debug = 0; + int dir = circulation( x, y, npts ); + if ( debug ) + { + if (( xclp[0] == xmin && xclp[iclp - 1] == xmax ) || + ( xclp[0] == xmax && xclp[iclp - 1] == xmin ) || + ( yclp[0] == ymin && yclp[iclp - 1] == ymax ) || + ( yclp[0] == ymax && yclp[iclp - 1] == ymin ) || + ( xclp[0] == xmin && yclp[iclp - 1] == ymin ) || + ( yclp[0] == ymin && xclp[iclp - 1] == xmin ) || + ( xclp[0] == xmax && yclp[iclp - 1] == ymin ) || + ( yclp[0] == ymin && xclp[iclp - 1] == xmax ) || + ( xclp[0] == xmax && yclp[iclp - 1] == ymax ) || + ( yclp[0] == ymax && xclp[iclp - 1] == xmax ) || + ( xclp[0] == xmin && yclp[iclp - 1] == ymax ) || + ( yclp[0] == ymax && xclp[iclp - 1] == xmin )) + { + printf( "dir=%d, clipped points:\n", dir ); + for ( i = 0; i < iclp; i++ ) + printf( " x[%d]=%d y[%d]=%d", i, xclp[i], i, yclp[i] ); + printf( "\n" ); + printf( "pre-clipped points:\n" ); + for ( i = 0; i < npts; i++ ) + printf( " x[%d]=%d y[%d]=%d", i, x[i], i, y[i] ); + printf( "\n" ); + } + } + + /* The cases where the fill region is divided 2/2 */ + /* Divided horizontally */ + if ( xclp[0] == xmin && xclp[iclp - 1] == xmax ) + { + if ( dir > 0 ) + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + else + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + } + else if ( xclp[0] == xmax && xclp[iclp - 1] == xmin ) + { + if ( dir > 0 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + else + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + } + + /* Divided vertically */ + else if ( yclp[0] == ymin && yclp[iclp - 1] == ymax ) + { + if ( dir > 0 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + else + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + } + else if ( yclp[0] == ymax && yclp[iclp - 1] == ymin ) + { + if ( dir > 0 ) + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + else + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + } + + /* The cases where the fill region is divided 3/1 -- + * LL LR UR UL + +-----+ +-----+ +-----+ +-----+ + | | | | | \| |/ | + | | | | | | | | + |\ | | /| | | | | + +-----+ +-----+ +-----+ +-----+ + * + * Note when we go the long way around, if the direction is reversed the + * three vertices must be visited in the opposite order. + */ + /* LL, short way around */ + else if (( xclp[0] == xmin && yclp[iclp - 1] == ymin && dir < 0 ) || + ( yclp[0] == ymin && xclp[iclp - 1] == xmin && dir > 0 )) + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + /* LL, long way around, counterclockwise */ + else if (( xclp[0] == xmin && yclp[iclp - 1] == ymin && dir > 0 )) + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + /* LL, long way around, clockwise */ + else if (( yclp[0] == ymin && xclp[iclp - 1] == xmin && dir < 0 )) + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + /* LR, short way around */ + else if (( xclp[0] == xmax && yclp[iclp - 1] == ymin && dir > 0 ) || + ( yclp[0] == ymin && xclp[iclp - 1] == xmax && dir < 0 )) + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + /* LR, long way around, counterclockwise */ + else if ( yclp[0] == ymin && xclp[iclp - 1] == xmax && dir > 0 ) + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + /* LR, long way around, clockwise */ + else if ( xclp[0] == xmax && yclp[iclp - 1] == ymin && dir < 0 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + /* UR, short way around */ + else if (( xclp[0] == xmax && yclp[iclp - 1] == ymax && dir < 0 ) || + ( yclp[0] == ymax && xclp[iclp - 1] == xmax && dir > 0 )) + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + /* UR, long way around, counterclockwise */ + else if ( xclp[0] == xmax && yclp[iclp - 1] == ymax && dir > 0 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + } + /* UR, long way around, clockwise */ + else if ( yclp[0] == ymax && xclp[iclp - 1] == xmax && dir < 0 ) + { + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + /* UL, short way around */ + else if (( xclp[0] == xmin && yclp[iclp - 1] == ymax && dir > 0 ) || + ( yclp[0] == ymax && xclp[iclp - 1] == xmin && dir < 0 )) + { + xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; + } + /* UL, long way around, counterclockwise */ + else if ( yclp[0] == ymax && xclp[iclp - 1] == xmin && dir > 0 ) + { + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + } + /* UL, long way around, clockwise */ + else if ( xclp[0] == xmin && yclp[iclp - 1] == ymax && dir < 0 ) + { + xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; + xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; + xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; + } + } + +/* Check for the case that only one side has been crossed + * (AM) Just checking a single point turns out not to be + * enough, apparently the crossed_*1 and crossed_*2 variables + * are not quite what I expected. + */ + if ( crossed_left + crossed_right + crossed_down + crossed_up == 1 && + inside_lb + inside_rb + inside_lu + inside_ru == 4 ) + { + int dir = circulation( x, y, npts ); + PLINT xlim[4], ylim[4]; + int insert; + int incr; + + xlim[0] = xmin; ylim[0] = ymin; + xlim[1] = xmax; ylim[1] = ymin; + xlim[2] = xmax; ylim[2] = ymax; + xlim[3] = xmin; ylim[3] = ymax; + if ( dir > 0 ) + { + incr = 1; + insert = 0 * crossed_left + 1 * crossed_down + 2 * crossed_right + + 3 * crossed_up; + } + else + { + incr = -1; + insert = 3 * crossed_left + 2 * crossed_up + 1 * crossed_right + + 0 * crossed_down; + } + for ( i = 0; i < 4; i++ ) + { + xclp[iclp] = xlim[insert]; + yclp[iclp] = ylim[insert]; + iclp++; + insert += incr; + if ( insert > 3 ) insert = 0; + if ( insert < 0 ) insert = 3; + } + } + +/* Draw the sucker */ + if ( iclp >= 3 ) + ( *draw )( xclp, yclp, iclp ); + + if ( xclp != _xclp ) + { + free( xclp ); + free( yclp ); + } +} + +/*----------------------------------------------------------------------*\ + * int circulation() + * + * Returns the circulation direction for a given polyline: positive is + * counterclockwise, negative is clockwise (right hand rule). + * + * Used to get the circulation of the fill polygon around the bounding box, + * when the fill polygon is larger than the bounding box. Counts left + * (positive) vs right (negative) hand turns using a cross product, instead of + * performing all the expensive trig calculations needed to get this 100% + * correct. For the fill cases encountered in plplot, this treatment should + * give the correct answer most of the time, by far. When used with plshades, + * the typical return value is 3 or -3, since 3 turns are necessary in order + * to complete the fill region. Only for really oddly shaped fill regions + * will it give the wrong answer. + * + * AM: + * Changed the computation: use the outer product to compute the surface + * area, the sign determines if the polygon is followed clockwise or + * counterclockwise. This is more reliable. Floating-point numbers + * are used to avoid overflow. + \*----------------------------------------------------------------------*/ + +static int +circulation( PLINT *x, PLINT *y, PLINT npts ) +{ + PLFLT xproduct; + int direction = 0; + PLFLT x1, y1, x2, y2, x3, y3; + int i; + + xproduct = 0.0; + x1 = x[0]; + y1 = y[0]; + for ( i = 1; i < npts - 2; i++ ) + { + x2 = x[i + 1]; + y2 = y[i + 1]; + x3 = x[i + 2]; + y3 = y[i + 2]; + xproduct = xproduct + ( x2 - x1 ) * ( y3 - y2 ) - ( y2 - y1 ) * ( x3 - x2 ); + } + + if ( xproduct > 0.0 ) direction = 1; + if ( xproduct < 0.0 ) direction = -1; + return direction; +} + +/*----------------------------------------------------------------------*\ + * int pointinpolygon() + * + * PLINT wrapper for plP_pointinpolygon. + \*----------------------------------------------------------------------*/ + +static int +pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ) +{ + int i, return_value; + PLFLT *xflt, *yflt; + if (( xflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) + { + plexit( "pointinpolygon: Insufficient memory" ); + } + if (( yflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) + { + plexit( "pointinpolygon: Insufficient memory" ); + } + for ( i = 0; i < n; i++ ) + { + xflt[i] = (PLFLT) x[i]; + yflt[i] = (PLFLT) y[i]; + } + return_value = plP_pointinpolygon( n, xflt, yflt, (PLFLT) xp, (PLFLT) yp ); + free( xflt ); + free( yflt ); + return return_value; +} +/*----------------------------------------------------------------------*\ + * int plP_pointinpolygon() + * + * Returns 1 if the point is inside the polygon, 0 otherwise + * Notes: + * Points on the polygon are considered to be outside. + * This "Ray casting algorithm" has been described in + * http://en.wikipedia.org/wiki/Point_in_polygon. + * Logic still needs to be inserted to take care of the "ray passes + * through vertex" problem in a numerically robust way. + \*----------------------------------------------------------------------*/ + +int +plP_pointinpolygon( PLINT n, PLFLT *x, PLFLT *y, PLFLT xp, PLFLT yp ) +{ + int i; + int count_crossings; + PLFLT x1, y1, x2, y2, xout, yout, xmax; + PLFLT xvp, yvp, xvv, yvv, xv1, yv1, xv2, yv2; + PLFLT inprod1, inprod2; + + count_crossings = 0; + + + /* Determine a point outside the polygon */ + + xmax = x[0]; + xout = x[0]; + yout = y[0]; + for ( i = 0; i < n; i++ ) + { + if ( xout > x[i] ) + { + xout = x[i]; + } + if ( xmax < x[i] ) + { + xmax = x[i]; + } + } + xout = xout - ( xmax - xout ); + + /* Determine for each side whether the line segment between + * our two points crosses the vertex */ + + xvp = xp - xout; + yvp = yp - yout; + + for ( i = 0; i < n; i++ ) + { + x1 = x[i]; + y1 = y[i]; + if ( i < n - 1 ) + { + x2 = x[i + 1]; + y2 = y[i + 1]; + } + else + { + x2 = x[0]; + y2 = y[0]; + } + + /* Skip zero-length segments */ + if ( x1 == x2 && y1 == y2 ) + { + continue; + } + + /* Line through the two fixed points: + * Are x1 and x2 on either side? */ + xv1 = x1 - xout; + yv1 = y1 - yout; + xv2 = x2 - xout; + yv2 = y2 - yout; + inprod1 = xv1 * yvp - yv1 * xvp; /* Well, with the normal vector */ + inprod2 = xv2 * yvp - yv2 * xvp; + if ( inprod1 * inprod2 >= 0.0 ) + { + /* No crossing possible! */ + continue; + } + + /* Line through the two vertices: + * Are xout and xp on either side? */ + xvv = x2 - x1; + yvv = y2 - y1; + xv1 = xp - x1; + yv1 = yp - y1; + xv2 = xout - x1; + yv2 = yout - y1; + inprod1 = xv1 * yvv - yv1 * xvv; + inprod2 = xv2 * yvv - yv2 * xvv; + if ( inprod1 * inprod2 >= 0.0 ) + { + /* No crossing possible! */ + continue; + } + + /* We do have a crossing */ + count_crossings++; + } + + /* Return the result: an even number of crossings means the + * point is outside the polygon */ + + return ( count_crossings % 2 ); +} Modified: trunk/src/plline.c =================================================================== --- trunk/src/plline.c 2009-11-30 12:05:36 UTC (rev 10650) +++ trunk/src/plline.c 2009-11-30 17:57:25 UTC (rev 10651) @@ -37,12 +37,6 @@ static void pllclp( PLINT *x, PLINT *y, PLINT npts ); -/* Get clipped endpoints */ - -static int -clipline( PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2, - PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax ); - /* General line-drawing routine. Takes line styles into account. */ static void @@ -55,9 +49,6 @@ /* Determines if a point is inside a polygon or not */ -static int -pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ); - /*----------------------------------------------------------------------*\ * void pljoin() * @@ -593,7 +584,8 @@ drawable = ( INSIDE( x1, y1 ) && INSIDE( x2, y2 )); if ( !drawable ) - drawable = !clipline( &x1, &y1, &x2, &y2, xmin, xmax, ymin, ymax ); + drawable = !plP_clipline( &x1, &y1, &x2, &y2, + xmin, xmax, ymin, ymax ); if ( drawable ) { @@ -650,521 +642,13 @@ } /*----------------------------------------------------------------------*\ - * int circulation() + * int plP_clipline() * - * Returns the circulation direction for a given polyline: positive is - * counterclockwise, negative is clockwise (right hand rule). - * - * Used to get the circulation of the fill polygon around the bounding box, - * when the fill polygon is larger than the bounding box. Counts left - * (positive) vs right (negative) hand turns using a cross product, instead of - * performing all the expensive trig calculations needed to get this 100% - * correct. For the fill cases encountered in plplot, this treatment should - * give the correct answer most of the time, by far. When used with plshades, - * the typical return value is 3 or -3, since 3 turns are necessary in order - * to complete the fill region. Only for really oddly shaped fill regions - * will it give the wrong answer. - * - * AM: - * Changed the computation: use the outer product to compute the surface - * area, the sign determines if the polygon is followed clockwise or - * counterclockwise. This is more reliable. Floating-point numbers - * are used to avoid overflow. - \*----------------------------------------------------------------------*/ - -static int -circulation( PLINT *x, PLINT *y, PLINT npts ) -{ - PLFLT xproduct; - int direction = 0; - PLFLT x1, y1, x2, y2, x3, y3; - int i; - - xproduct = 0.0; - x1 = x[0]; - y1 = y[0]; - for ( i = 1; i < npts - 2; i++ ) - { - x2 = x[i + 1]; - y2 = y[i + 1]; - x3 = x[i + 2]; - y3 = y[i + 2]; - xproduct = xproduct + ( x2 - x1 ) * ( y3 - y2 ) - ( y2 - y1 ) * ( x3 - x2 ); - } - - if ( xproduct > 0.0 ) direction = 1; - if ( xproduct < 0.0 ) direction = -1; - return direction; -} - -/*----------------------------------------------------------------------*\ - * void plP_plfclp() - * - * Fills a polygon within the clip limits. - \*----------------------------------------------------------------------*/ - -void -plP_plfclp( PLINT *x, PLINT *y, PLINT npts, - PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax, - void ( *draw )( short *, short *, PLINT )) -{ - PLINT i, x1, x2, y1, y2; - int iclp = 0, iout = 2; - short _xclp[2 * PL_MAXPOLY + 2], _yclp[2 * PL_MAXPOLY + 2]; - short *xclp, *yclp; - int drawable; - int crossed_xmin1 = 0, crossed_xmax1 = 0; - int crossed_ymin1 = 0, crossed_ymax1 = 0; - int crossed_xmin2 = 0, crossed_xmax2 = 0; - int crossed_ymin2 = 0, crossed_ymax2 = 0; - int crossed_up = 0, crossed_down = 0; - int crossed_left = 0, crossed_right = 0; - int inside_lb; - int inside_lu; - int inside_rb; - int inside_ru; - -/* Must have at least 3 points and draw() specified */ - if ( npts < 3 || !draw ) return; - - if ( npts < PL_MAXPOLY ) - { - xclp = _xclp; - yclp = _yclp; - } - else - { - if ((( xclp = (short *) malloc(( 2 * npts + 2 ) * sizeof ( short ))) == NULL ) || - (( yclp = (short *) malloc(( 2 * npts + 2 ) * sizeof ( short ))) == NULL )) - { - plexit( "plP_plfclp: Insufficient memory" ); - } - } - - - inside_lb = pointinpolygon( npts, x, y, xmin, ymin ); - inside_lu = pointinpolygon( npts, x, y, xmin, ymax ); - inside_rb = pointinpolygon( npts, x, y, xmax, ymin ); - inside_ru = pointinpolygon( npts, x, y, xmax, ymax ); - - for ( i = 0; i < npts - 1; i++ ) - { - x1 = x[i]; x2 = x[i + 1]; - y1 = y[i]; y2 = y[i + 1]; - - drawable = ( INSIDE( x1, y1 ) && INSIDE( x2, y2 )); - if ( !drawable ) - drawable = !clipline( &x1, &y1, &x2, &y2, xmin, xmax, ymin, ymax ); - - if ( drawable ) - { - /* Boundary crossing condition -- coming in. */ - crossed_xmin2 = ( x1 == xmin ); crossed_xmax2 = ( x1 == xmax ); - crossed_ymin2 = ( y1 == ymin ); crossed_ymax2 = ( y1 == ymax ); - - crossed_left = ( crossed_left || crossed_xmin2 ); - crossed_right = ( crossed_right || crossed_xmax2 ); - crossed_down = ( crossed_down || crossed_ymin2 ); - crossed_up = ( crossed_up || crossed_ymax2 ); - iout = iclp + 2; - /* If the first segment, just add it. */ - - if ( iclp == 0 ) - { - xclp[iclp] = x1; yclp[iclp] = y1; iclp++; - xclp[iclp] = x2; yclp[iclp] = y2; iclp++; - } - - /* Not first point. If first point of this segment matches up to the - * previous point, just add it. */ - - else if ( x1 == xclp[iclp - 1] && y1 == yclp[iclp - 1] ) - { - xclp[iclp] = x2; yclp[iclp] = y2; iclp++; - } - - /* Otherwise, we need to add both points, to connect the points in the - * polygon along the clip boundary. If we encircled a corner, we have - * to add that first. - */ - - else - { - /* Treat the case where we encircled two corners: - * Construct a polygon out of the subset of vertices - * Note that the direction is important too when adding - * the extra points */ - xclp[iclp + 1] = x2; yclp[iclp + 1] = y2; - xclp[iclp + 2] = x1; yclp[iclp + 2] = y1; - iout = iout - iclp + 1; - /* Upper two */ - if ((( crossed_xmin1 && crossed_xmax2 ) || - ( crossed_xmin2 && crossed_xmax1 )) && - inside_lu ) - { - if ( crossed_xmin1 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - else - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - } - /* Lower two */ - else if ((( crossed_xmin1 && crossed_xmax2 ) || - ( crossed_xmin2 && crossed_xmax1 )) && - inside_lb ) - { - if ( crossed_xmin1 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - else - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - } - /* Left two */ - else if ((( crossed_ymin1 && crossed_ymax2 ) || - ( crossed_ymin2 && crossed_ymax1 )) && - inside_lb ) - { - if ( crossed_ymin1 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - else - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - } - /* Right two */ - else if ((( crossed_ymin1 && crossed_ymax2 ) || - ( crossed_ymin2 && crossed_ymax1 )) && - inside_rb ) - { - if ( crossed_ymin1 ) - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - else - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - } - /* Now the case where we encircled one corner */ - /* Lower left */ - else if (( crossed_xmin1 && crossed_ymin2 ) || - ( crossed_ymin1 && crossed_xmin2 )) - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - /* Lower right */ - else if (( crossed_xmax1 && crossed_ymin2 ) || - ( crossed_ymin1 && crossed_xmax2 )) - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - /* Upper left */ - else if (( crossed_xmin1 && crossed_ymax2 ) || - ( crossed_ymax1 && crossed_xmin2 )) - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - /* Upper right */ - else if (( crossed_xmax1 && crossed_ymax2 ) || - ( crossed_ymax1 && crossed_xmax2 )) - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - - /* Now add current segment. */ - xclp[iclp] = x1; yclp[iclp] = y1; iclp++; - xclp[iclp] = x2; yclp[iclp] = y2; iclp++; - } - - /* Boundary crossing condition -- going out. */ - crossed_xmin1 = ( x2 == xmin ); crossed_xmax1 = ( x2 == xmax ); - crossed_ymin1 = ( y2 == ymin ); crossed_ymax1 = ( y2 == ymax ); - } - } - -/* Limit case - all vertices are outside of bounding box. So just fill entire - * box, *if* the bounding box is completely encircled. - */ - - if ( iclp == 0 ) - { - if ( inside_lb ) - { - xclp[0] = xmin; yclp[0] = ymin; - xclp[1] = xmax; yclp[1] = ymin; - xclp[2] = xmax; yclp[2] = ymax; - xclp[3] = xmin; yclp[3] = ymax; - xclp[4] = xmin; yclp[4] = ymin; - ( *draw )( xclp, yclp, 5 ); - - if ( xclp != _xclp ) - { - free( xclp ); - free( yclp ); - } - - - return; - } - } - -/* Now handle cases where fill polygon intersects two sides of the box */ - - if ( iclp >= 2 ) - { - int debug = 0; - int dir = circulation( x, y, npts ); - if ( debug ) - { - if (( xclp[0] == xmin && xclp[iclp - 1] == xmax ) || - ( xclp[0] == xmax && xclp[iclp - 1] == xmin ) || - ( yclp[0] == ymin && yclp[iclp - 1] == ymax ) || - ( yclp[0] == ymax && yclp[iclp - 1] == ymin ) || - ( xclp[0] == xmin && yclp[iclp - 1] == ymin ) || - ( yclp[0] == ymin && xclp[iclp - 1] == xmin ) || - ( xclp[0] == xmax && yclp[iclp - 1] == ymin ) || - ( yclp[0] == ymin && xclp[iclp - 1] == xmax ) || - ( xclp[0] == xmax && yclp[iclp - 1] == ymax ) || - ( yclp[0] == ymax && xclp[iclp - 1] == xmax ) || - ( xclp[0] == xmin && yclp[iclp - 1] == ymax ) || - ( yclp[0] == ymax && xclp[iclp - 1] == xmin )) - { - printf( "dir=%d, clipped points:\n", dir ); - for ( i = 0; i < iclp; i++ ) - printf( " x[%d]=%d y[%d]=%d", i, xclp[i], i, yclp[i] ); - printf( "\n" ); - printf( "pre-clipped points:\n" ); - for ( i = 0; i < npts; i++ ) - printf( " x[%d]=%d y[%d]=%d", i, x[i], i, y[i] ); - printf( "\n" ); - } - } - - /* The cases where the fill region is divided 2/2 */ - /* Divided horizontally */ - if ( xclp[0] == xmin && xclp[iclp - 1] == xmax ) - { - if ( dir > 0 ) - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - else - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - } - else if ( xclp[0] == xmax && xclp[iclp - 1] == xmin ) - { - if ( dir > 0 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - else - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - } - - /* Divided vertically */ - else if ( yclp[0] == ymin && yclp[iclp - 1] == ymax ) - { - if ( dir > 0 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - else - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - } - else if ( yclp[0] == ymax && yclp[iclp - 1] == ymin ) - { - if ( dir > 0 ) - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - else - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - } - - /* The cases where the fill region is divided 3/1 -- - * LL LR UR UL - +-----+ +-----+ +-----+ +-----+ - | | | | | \| |/ | - | | | | | | | | - |\ | | /| | | | | - +-----+ +-----+ +-----+ +-----+ - * - * Note when we go the long way around, if the direction is reversed the - * three vertices must be visited in the opposite order. - */ - /* LL, short way around */ - else if (( xclp[0] == xmin && yclp[iclp - 1] == ymin && dir < 0 ) || - ( yclp[0] == ymin && xclp[iclp - 1] == xmin && dir > 0 )) - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - /* LL, long way around, counterclockwise */ - else if (( xclp[0] == xmin && yclp[iclp - 1] == ymin && dir > 0 )) - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - /* LL, long way around, clockwise */ - else if (( yclp[0] == ymin && xclp[iclp - 1] == xmin && dir < 0 )) - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - /* LR, short way around */ - else if (( xclp[0] == xmax && yclp[iclp - 1] == ymin && dir > 0 ) || - ( yclp[0] == ymin && xclp[iclp - 1] == xmax && dir < 0 )) - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - /* LR, long way around, counterclockwise */ - else if ( yclp[0] == ymin && xclp[iclp - 1] == xmax && dir > 0 ) - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - /* LR, long way around, clockwise */ - else if ( xclp[0] == xmax && yclp[iclp - 1] == ymin && dir < 0 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - /* UR, short way around */ - else if (( xclp[0] == xmax && yclp[iclp - 1] == ymax && dir < 0 ) || - ( yclp[0] == ymax && xclp[iclp - 1] == xmax && dir > 0 )) - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - /* UR, long way around, counterclockwise */ - else if ( xclp[0] == xmax && yclp[iclp - 1] == ymax && dir > 0 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - } - /* UR, long way around, clockwise */ - else if ( yclp[0] == ymax && xclp[iclp - 1] == xmax && dir < 0 ) - { - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - /* UL, short way around */ - else if (( xclp[0] == xmin && yclp[iclp - 1] == ymax && dir > 0 ) || - ( yclp[0] == ymax && xclp[iclp - 1] == xmin && dir < 0 )) - { - xclp[iclp] = xmin; yclp[iclp] = ymax; iclp++; - } - /* UL, long way around, counterclockwise */ - else if ( yclp[0] == ymax && xclp[iclp - 1] == xmin && dir > 0 ) - { - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - } - /* UL, long way around, clockwise */ - else if ( xclp[0] == xmin && yclp[iclp - 1] == ymax && dir < 0 ) - { - xclp[iclp] = xmax; yclp[iclp] = ymax; iclp++; - xclp[iclp] = xmax; yclp[iclp] = ymin; iclp++; - xclp[iclp] = xmin; yclp[iclp] = ymin; iclp++; - } - } - -/* Check for the case that only one side has been crossed - * (AM) Just checking a single point turns out not to be - * enough, apparently the crossed_*1 and crossed_*2 variables - * are not quite what I expected. - */ - if ( crossed_left + crossed_right + crossed_down + crossed_up == 1 && - inside_lb + inside_rb + inside_lu + inside_ru == 4 ) - { - int dir = circulation( x, y, npts ); - PLINT xlim[4], ylim[4]; - int insert; - int incr; - - xlim[0] = xmin; ylim[0] = ymin; - xlim[1] = xmax; ylim[1] = ymin; - xlim[2] = xmax; ylim[2] = ymax; - xlim[3] = xmin; ylim[3] = ymax; - if ( dir > 0 ) - { - incr = 1; - insert = 0 * crossed_left + 1 * crossed_down + 2 * crossed_right + - 3 * crossed_up; - } - else - { - incr = -1; - insert = 3 * crossed_left + 2 * crossed_up + 1 * crossed_right + - 0 * crossed_down; - } - for ( i = 0; i < 4; i++ ) - { - xclp[iclp] = xlim[insert]; - yclp[iclp] = ylim[insert]; - iclp++; - insert += incr; - if ( insert > 3 ) insert = 0; - if ( insert < 0 ) insert = 3; - } - } - -/* Draw the sucker */ - if ( iclp >= 3 ) - ( *draw )( xclp, yclp, iclp ); - - if ( xclp != _xclp ) - { - free( xclp ); - free( yclp ); - } -} - -/*----------------------------------------------------------------------*\ - * int clipline() - * * Get clipped endpoints \*----------------------------------------------------------------------*/ -static int -clipline( PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2, +int +plP_clipline( PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2, PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax ) { PLINT t, dx, dy, flipx, flipy; @@ -1430,141 +914,3 @@ lasty = ytmp; } } - -/*----------------------------------------------------------------------*\ - * int pointinpolygon() - * - * PLINT wrapper for plP_pointinpolygon. - \*----------------------------------------------------------------------*/ - -static int -pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ) -{ - int i, return_value; - PLFLT *xflt, *yflt; - if (( xflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) - { - plexit( "pointinpolygon: Insufficient memory" ); - } - if (( yflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) - { - plexit( "pointinpolygon: Insufficient memory" ); - } - for ( i = 0; i < n; i++ ) - { - xflt[i] = (PLFLT) x[i]; - yflt[i] = (PLFLT) y[i]; - } - return_value = plP_pointinpolygon( n, xflt, yflt, (PLFLT) xp, (PLFLT) yp ); - free( xflt ); - free( yflt ); - return return_value; -} -/*----------------------------------------------------------------------*\ - * int plP_pointinpolygon() - * - * Returns 1 if the point is inside the polygon, 0 otherwise - * Notes: - * Points on the polygon are considered to be outside. - * This "Ray casting algorithm" has been described in - * http://en.wikipedia.org/wiki/Point_in_polygon. - * Logic still needs to be inserted to take care of the "ray passes - * through vertex" problem in a numerically robust way. - \*----------------------------------------------------------------------*/ - -int -plP_pointinpolygon( PLINT n, PLFLT *x, PLFLT *y, PLFLT xp, PLFLT yp ) -{ - int i; - int count_crossings; - PLFLT x1, y1, x2, y2, xout, yout, xmax; - PLFLT xvp, yvp, xvv, yvv, xv1, yv1, xv2, yv2; - PLFLT inprod1, inprod2; - - count_crossings = 0; - - - /* Determine a point outside the polygon */ - - xmax = x[0]; - xout = x[0]; - yout = y[0]; - for ( i = 0; i < n; i++ ) - { - if ( xout > x[i] ) - { - xout = x[i]; - } - if ( xmax < x[i] ) - { - xmax = x[i]; - } - } - xout = xout - ( xmax - xout ); - - /* Determine for each side whether the line segment between - * our two points crosses the vertex */ - - xvp = xp - xout; - yvp = yp - yout; - - for ( i = 0; i < n; i++ ) - { - x1 = x[i]; - y1 = y[i]; - if ( i < n - 1 ) - { - x2 = x[i + 1]; - y2 = y[i + 1]; - } - else - { - x2 = x[0]; - y2 = y[0]; - } - - /* Skip zero-length segments */ - if ( x1 == x2 && y1 == y2 ) - { - continue; - } - - /* Line through the two fixed points: - * Are x1 and x2 on either side? */ - xv1 = x1 - xout; - yv1 = y1 - yout; - xv2 = x2 - xout; - yv2 = y2 - yout; - inprod1 = xv1 * yvp - yv1 * xvp; /* Well, with the normal vector */ - inprod2 = xv2 * yvp - yv2 * xvp; - if ( inprod1 * inprod2 >= 0.0 ) - { - /* No crossing possible! */ - continue; - } - - /* Line through the two vertices: - * Are xout and xp on either side? */ - xvv = x2 - x1; - yvv = y2 - y1; - xv1 = xp - x1; - yv1 = yp - y1; - xv2 = xout - x1; - yv2 = yout - y1; - inprod1 = xv1 * yvv - yv1 * xvv; - inprod2 = xv2 * yvv - yv2 * xvv; - if ( inprod1 * inprod2 >= 0.0 ) - { - /* No crossing possible! */ - continue; - } - - /* We do have a crossing */ - count_crossings++; - } - - /* Return the result: an even number of crossings means the - * point is outside the polygon */ - - return ( count_crossings % 2 ); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-01 05:20:10
|
Revision: 10652 http://plplot.svn.sourceforge.net/plplot/?rev=10652&view=rev Author: airwin Date: 2009-12-01 05:20:00 +0000 (Tue, 01 Dec 2009) Log Message: ----------- Style recent changes. Modified Paths: -------------- trunk/include/plplotP.h trunk/src/plline.c Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-11-30 17:57:25 UTC (rev 10651) +++ trunk/include/plplotP.h 2009-12-01 05:20:00 UTC (rev 10652) @@ -472,7 +472,7 @@ int plP_clipline( PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2, - PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax ); + PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax ); /* Stores hex digit value into FCI (font characterization integer). */ void Modified: trunk/src/plline.c =================================================================== --- trunk/src/plline.c 2009-11-30 17:57:25 UTC (rev 10651) +++ trunk/src/plline.c 2009-12-01 05:20:00 UTC (rev 10652) @@ -649,7 +649,7 @@ int plP_clipline( PLINT *p_x1, PLINT *p_y1, PLINT *p_x2, PLINT *p_y2, - PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax ) + PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax ) { PLINT t, dx, dy, flipx, flipy; double dydx = 0, dxdy = 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-01 05:46:50
|
Revision: 10653 http://plplot.svn.sourceforge.net/plplot/?rev=10653&view=rev Author: airwin Date: 2009-12-01 05:46:38 +0000 (Tue, 01 Dec 2009) Log Message: ----------- Implement native driver gradients for all qt raster devices and -dev svgqt. Modified Paths: -------------- trunk/bindings/qt_gui/plqt.cpp trunk/drivers/qt.cpp trunk/include/qt.h Modified: trunk/bindings/qt_gui/plqt.cpp =================================================================== --- trunk/bindings/qt_gui/plqt.cpp 2009-12-01 05:20:00 UTC (rev 10652) +++ trunk/bindings/qt_gui/plqt.cpp 2009-12-01 05:46:38 UTC (rev 10653) @@ -372,6 +372,30 @@ m_painterP->setBrush( B ); } +void QtPLDriver::setGradient( int x1, int x2, int y1, int y2, + int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ) +{ + if ( !m_painterP->isActive() || ncol1 < 2 ) return; + + int i; + qreal stop_arg; + QGradient linear_gradient; + QGradientStops stops; + + linear_gradient = QLinearGradient( + QPointF((qreal) ( x1 * downscale ), (qreal) ( m_dHeight - y1 * downscale )), + QPointF((qreal) ( x2 * downscale ), (qreal) ( m_dHeight - y2 * downscale ))); + + for ( i = 0; i < ncol1; i++ ) + { + stop_arg = (qreal) i / (qreal) ( ncol1 - 1 ); + stops << QGradientStop( stop_arg, QColor( r[i], g[i], + b[i], (int) ( alpha[i] * 255 ))); + } + linear_gradient.setStops( stops ); + m_painterP->setBrush( linear_gradient ); +} + void QtPLDriver::setWidth( PLINT w ) { if ( !m_painterP->isActive()) return; Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-12-01 05:20:00 UTC (rev 10652) +++ trunk/drivers/qt.cpp 2009-12-01 05:46:38 UTC (rev 10653) @@ -240,10 +240,11 @@ plParseDrvOpts( qt_options ); /* Stream setup */ - pls->color = 1; - pls->plbuf_write = 0; - pls->dev_fill0 = 1; - pls->dev_fill1 = 0; + pls->color = 1; + pls->plbuf_write = 0; + pls->dev_fill0 = 1; + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -334,6 +335,8 @@ void plD_esc_rasterqt( PLStream * pls, PLINT op, void* ptr ) { short *xa, *ya; + int *r, *g, *b; + qreal *alpha; PLINT i; QtRasterDevice * widget = (QtRasterDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) @@ -367,6 +370,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new int [pls->ncol1]; + g = new int [pls->ncol1]; + b = new int [pls->ncol1]; + alpha = new qreal [pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ @@ -622,10 +657,11 @@ plParseDrvOpts( qt_options ); /* Stream setup */ - pls->color = 1; - pls->plbuf_write = 0; - pls->dev_fill0 = 1; - pls->dev_fill1 = 0; + pls->color = 1; + pls->plbuf_write = 0; + pls->dev_fill0 = 1; + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -733,6 +769,8 @@ void plD_esc_svgqt( PLStream * pls, PLINT op, void* ptr ) { short *xa, *ya; + int *r, *g, *b; + qreal *alpha; PLINT i; QtSVGDevice * widget = (QtSVGDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) @@ -759,6 +797,39 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new int [pls->ncol1]; + g = new int [pls->ncol1]; + b = new int [pls->ncol1]; + alpha = new qreal [pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ Modified: trunk/include/qt.h =================================================================== --- trunk/include/qt.h 2009-12-01 05:20:00 UTC (rev 10652) +++ trunk/include/qt.h 2009-12-01 05:46:38 UTC (rev 10653) @@ -128,6 +128,8 @@ virtual void drawPolygon( short * x, short * y, PLINT npts ); virtual void drawText( PLStream* pls, EscText* txt ); virtual void setColor( int r, int g, int b, double alpha ); + virtual void setGradient( int x1, int x2, int y1, int y2, + int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ); virtual void setBackgroundColor( int r, int g, int b, double alpha ){} virtual void setWidth( PLINT w ); // Set pen to draw solid strokes (called after drawing dashed strokes) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-02 01:13:20
|
Revision: 10660 http://plplot.svn.sourceforge.net/plplot/?rev=10660&view=rev Author: airwin Date: 2009-12-02 01:13:12 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Implement plgradient for D bindings and make D examples 25 and 30 produce consistent results with their C counterparts (which use plgradient). Modified Paths: -------------- trunk/bindings/d/plplot.d trunk/examples/d/x25d.d trunk/examples/d/x30d.d Modified: trunk/bindings/d/plplot.d =================================================================== --- trunk/bindings/d/plplot.d 2009-12-02 01:10:08 UTC (rev 10659) +++ trunk/bindings/d/plplot.d 2009-12-02 01:13:12 UTC (rev 10660) @@ -262,6 +262,14 @@ fnam=toString(fnam.ptr); } +/* Draw gradient in polygon. */ +void plgradient(PLFLT[] x, PLFLT[] y, PLFLT angle) +{ + PLINT n=x.length; + assert(n==y.length, "plgradient(): Arrays must be of same length!"); + c_plgradient(n, x.ptr, y.ptr, angle); +} + /* grid irregularly sampled data */ void plgriddata(PLFLT[] x, PLFLT[] y, PLFLT[] z, PLFLT[] xg, PLFLT[] yg, PLFLT[][] zg, PLINT type, PLFLT data) { @@ -1264,6 +1272,7 @@ alias c_plgfont plgfont; alias c_plglevel plglevel; alias c_plgpage plgpage; +alias c_plgradient plgrdient; alias c_plgra plgra; //alias c_plgriddata plgriddata; alias c_plgspa plgspa; @@ -1590,7 +1599,10 @@ /* Switches to graphics screen. */ void c_plgra(); - /* grid irregularly sampled data */ +/* Draw gradient in polygon. */ +void c_plgradient( PLINT n, PLFLT *x, PLFLT *y, PLFLT angle ); + +/* grid irregularly sampled data */ void c_plgriddata(PLFLT *x, PLFLT *y, PLFLT *z, PLINT npts, PLFLT *xg, PLINT nptsx, PLFLT *yg, PLINT nptsy, PLFLT **zg, PLINT type, PLFLT data); Modified: trunk/examples/d/x25d.d =================================================================== --- trunk/examples/d/x25d.d 2009-12-02 01:10:08 UTC (rev 10659) +++ trunk/examples/d/x25d.d 2009-12-02 01:13:12 UTC (rev 10660) @@ -43,11 +43,12 @@ [-120.0, 120.0] ]; PLFLT[] x0, y0; - x0.length = 4; - y0.length = 4; + for(int k=0; k<2; k++) { for(int j=0; j<4; j++) { switch(j) { case 0: + x0.length = 4; + y0.length = 4; /* Polygon 1: a diamond */ x0[] = [ 0.0, -100.0, 0.0, 100.0 ]; y0[] = [-100.0, 0.0, 100.0, 0.0 ]; @@ -80,12 +81,16 @@ plbox("bc", 1.0, 0, "bcnv", 10.0, 0); plcol0(1); plpsty(0); - plfill(x0, y0); + if(k ==0) + plfill(x0, y0); + else + plgradient(x0, y0, 45.); plcol0(2); pllsty(1); plline(x0, y0); } } + } /* Don't forget to call plend() to finish off! */ plend(); Modified: trunk/examples/d/x30d.d =================================================================== --- trunk/examples/d/x30d.d 2009-12-02 01:10:08 UTC (rev 10659) +++ trunk/examples/d/x30d.d 2009-12-02 01:13:12 UTC (rev 10660) @@ -130,28 +130,24 @@ } } - /* The overlaid box is drawn using plshades with a color map that is */ - /* the same color but has a linearly varying transparency. */ - /* Create the color map with 128 colors and use plscmap1la to initialize */ - /* the color values with a linear varying transparency (or alpha) */ + /* the color values with a linearly varying red transparency (or alpha) */ plscmap1n(128); plscmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev); - /* Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will */ - /* used for the shade plot. plshades will use linear interpolation to */ - /* calculate the z values of all the intermediate points in this array. */ - PLFLT[][] z = [ [0.0, 1.0], [0.0, 1.0] ]; + /* Use that cmap1 to create a transparent red gradient for the whole + * window. */ + px[0] = 0.; + px[1] = 1.; + px[2] = 1.; + px[3] = 0.; - /* Set the color levels array. These levels are also between 0.0 and 1.0 */ - PLFLT[] clevel; - clevel.length=101; - for(int i=0; i<clevel.length; i++) - clevel[i] = 0.01*i; + py[0] = 0.; + py[1] = 0.; + py[2] = 1.; + py[3] = 1.; - /* Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y coordinate ranges */ - /* such that it fills the entire plotting area. */ - plshades(z, null, 0.0, 1.0, 0.0, 1.0, clevel, 0, -1, 2, 1); + plgradient( px, py, 90. ); plend(); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-02 03:36:33
|
Revision: 10663 http://plplot.svn.sourceforge.net/plplot/?rev=10663&view=rev Author: airwin Date: 2009-12-02 03:36:24 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Implement plgradient for f77 bindings and make f77 examples 25 and 30 produce consistent results with their C counterparts (which use plgradient). Modified Paths: -------------- trunk/bindings/f77/plstubs.h trunk/bindings/f77/scstubs.c trunk/examples/f77/x25f.fm4 trunk/examples/f77/x30f.fm4 Modified: trunk/bindings/f77/plstubs.h =================================================================== --- trunk/bindings/f77/plstubs.h 2009-12-02 01:51:25 UTC (rev 10662) +++ trunk/bindings/f77/plstubs.h 2009-12-02 03:36:24 UTC (rev 10663) @@ -218,6 +218,7 @@ #define PLGLEVEL FNAME( PLGLEVEL, plglevel ) #define PLGPAGE FNAME( PLGPAGE, plgpage ) #define PLGRA FNAME( PLGRA, plgra ) +#define PLGRADIENT FNAME( PLGRADIENT, plgradient ) #define PLGRIDDATA FNAME( PLGRIDDATA, plgriddata ) #define PLGSPA FNAME( PLGSPA, plgspa ) #define PLGSTRM FNAME( PLGSTRM, plgstrm ) Modified: trunk/bindings/f77/scstubs.c =================================================================== --- trunk/bindings/f77/scstubs.c 2009-12-02 01:51:25 UTC (rev 10662) +++ trunk/bindings/f77/scstubs.c 2009-12-02 03:36:24 UTC (rev 10663) @@ -368,6 +368,12 @@ } void +PLGRADIENT( PLINT *n, PLFLT *x, PLFLT *y, PLFLT *angle ) +{ + c_plgradient( *n, x, y, *angle ); +} + +void PLGSPA( PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax ) { c_plgspa( xmin, xmax, ymin, ymax ); Modified: trunk/examples/f77/x25f.fm4 =================================================================== --- trunk/examples/f77/x25f.fm4 2009-12-02 01:51:25 UTC (rev 10662) +++ trunk/examples/f77/x25f.fm4 2009-12-02 03:36:24 UTC (rev 10663) @@ -1,13 +1,13 @@ -c $Id$ -c -c Filling and clipping polygons. -c -c -c -------------------------------------------------------------------------- -c main -c -c Test program for filling polygons and proper clipping -c -------------------------------------------------------------------------- +c $Id$ +c +c Filling and clipping polygons. +c +c +c -------------------------------------------------------------------------- +c main +c +c Test program for filling polygons and proper clipping +c -------------------------------------------------------------------------- program x25f @@ -16,8 +16,7 @@ integer PL_PARSE_FULL parameter(PL_PARSE_FULL = 1) - integer i - integer j + integer i,j,k integer npts real*8 xextreme(2,10) real*8 yextreme(2,10) @@ -25,94 +24,100 @@ real*8 y0(10) data ( xextreme(1,i), xextreme(2,i), yextreme(1,i), yextreme(2,i), - & i=1,9) / - & -120.0, 120.0, -120.0, 120.0, - & -120.0, 120.0, 20.0, 120.0, - & -120.0, 120.0, -20.0, 120.0, - & -80.0, 80.0, -20.0, 120.0, - & -220.0, -120.0, -120.0, 120.0, - & -20.0, 20.0, -120.0, 120.0, - & -20.0, 20.0, -20.0, 20.0, - & -80.0, 80.0, -80.0, 80.0, - & 20.0, 120.0, -120.0, 120.0/ + & i=1,9) / + & -120.0, 120.0, -120.0, 120.0, + & -120.0, 120.0, 20.0, 120.0, + & -120.0, 120.0, -20.0, 120.0, + & -80.0, 80.0, -20.0, 120.0, + & -220.0, -120.0, -120.0, 120.0, + & -20.0, 20.0, -120.0, 120.0, + & -20.0, 20.0, -20.0, 20.0, + & -80.0, 80.0, -80.0, 80.0, + & 20.0, 120.0, -120.0, 120.0/ npts = 0 -c Parse and process command line arguments +c Parse and process command line arguments call plparseopts(PL_PARSE_FULL) -c Initialize plplot +c Initialize plplot call plssub(3,3) call plinit() - do 120 j = 1,4 + do k = 1,2 + do j = 1,4 - if ( j .eq. 1 ) then -c Polygon 1: a diamond - x0(1) = 0 ; y0(1) = -100 - x0(2) = -100 ; y0(2) = 0 - x0(3) = 0 ; y0(3) = 100 - x0(4) = 100 ; y0(4) = 0 - npts = 4 - endif - if ( j .eq. 2 ) then -c Polygon 1: a diamond - reverse direction - x0(4) = 0 ; y0(4) = -100 - x0(3) = -100 ; y0(3) = 0 - x0(2) = 0 ; y0(2) = 100 - x0(1) = 100 ; y0(1) = 0 - npts = 4 - endif - if ( j .eq. 3 ) then -c Polygon 2: a square with punctures - x0(1) = -100 ; y0(1) = -100 - x0(2) = -100 ; y0(2) = -80 - x0(3) = 80 ; y0(3) = 0 - x0(4) = -100 ; y0(4) = 80 - x0(5) = -100 ; y0(5) = 100 - x0(6) = -80 ; y0(6) = 100 - x0(7) = 0 ; y0(7) = 80 - x0(8) = 80 ; y0(8) = 100 - x0(9) = 100 ; y0(9) = 100 - x0(10) = 100 ; y0(10) = -100 - npts = 10 - endif - if ( j .eq. 4 ) then -c Polygon 2: a square with punctures - reversed direction - x0(10) = -100 ; y0(10) = -100 - x0(9) = -100 ; y0(9) = -80 - x0(8) = 80 ; y0(8) = 0 - x0(7) = -100 ; y0(7) = 80 - x0(6) = -100 ; y0(6) = 100 - x0(5) = -80 ; y0(5) = 100 - x0(4) = 0 ; y0(4) = 80 - x0(3) = 80 ; y0(3) = 100 - x0(2) = 100 ; y0(2) = 100 - x0(1) = 100 ; y0(1) = -100 - npts = 10 - endif + if ( j .eq. 1 ) then +c Polygon 1: a diamond + x0(1) = 0 ; y0(1) = -100 + x0(2) = -100 ; y0(2) = 0 + x0(3) = 0 ; y0(3) = 100 + x0(4) = 100 ; y0(4) = 0 + npts = 4 + endif + if ( j .eq. 2 ) then +c Polygon 1: a diamond - reverse direction + x0(4) = 0 ; y0(4) = -100 + x0(3) = -100 ; y0(3) = 0 + x0(2) = 0 ; y0(2) = 100 + x0(1) = 100 ; y0(1) = 0 + npts = 4 + endif + if ( j .eq. 3 ) then +c Polygon 2: a square with punctures + x0(1) = -100 ; y0(1) = -100 + x0(2) = -100 ; y0(2) = -80 + x0(3) = 80 ; y0(3) = 0 + x0(4) = -100 ; y0(4) = 80 + x0(5) = -100 ; y0(5) = 100 + x0(6) = -80 ; y0(6) = 100 + x0(7) = 0 ; y0(7) = 80 + x0(8) = 80 ; y0(8) = 100 + x0(9) = 100 ; y0(9) = 100 + x0(10) = 100 ; y0(10) = -100 + npts = 10 + endif + if ( j .eq. 4 ) then +c Polygon 2: a square with punctures - reversed direction + x0(10) = -100 ; y0(10) = -100 + x0(9) = -100 ; y0(9) = -80 + x0(8) = 80 ; y0(8) = 0 + x0(7) = -100 ; y0(7) = 80 + x0(6) = -100 ; y0(6) = 100 + x0(5) = -80 ; y0(5) = 100 + x0(4) = 0 ; y0(4) = 80 + x0(3) = 80 ; y0(3) = 100 + x0(2) = 100 ; y0(2) = 100 + x0(1) = 100 ; y0(1) = -100 + npts = 10 + endif - do 110 i = 1,9 - call pladv(0) - call plvsta() - call plwind(xextreme(1,i), xextreme(2,i), - & yextreme(1,i), yextreme(2,i)) + do i = 1,9 + call pladv(0) + call plvsta() + call plwind(xextreme(1,i), xextreme(2,i), + & yextreme(1,i), yextreme(2,i)) - call plcol0(2) - call plbox('bc', 1.0d0, 0, 'bcnv', 10.0d0, 0) - call plcol0(1) - call plpsty(0) - call plfill(npts,x0,y0) - call plcol0(2) - call pllsty(1) - call plline(npts,x0,y0) - 110 continue - 120 continue + call plcol0(2) + call plbox('bc', 1.0d0, 0, 'bcnv', 10.0d0, 0) + call plcol0(1) + call plpsty(0) + if(k.eq.1) then + call plfill(npts,x0,y0) + else + call plgradient(npts,x0,y0,45.d0) + endif + call plcol0(2) + call pllsty(1) + call plline(npts,x0,y0) + enddo + enddo + enddo -c Don't forget to call plend() to finish off! +c Don't forget to call plend() to finish off! call plend() end Modified: trunk/examples/f77/x30f.fm4 =================================================================== --- trunk/examples/f77/x30f.fm4 2009-12-02 01:51:25 UTC (rev 10662) +++ trunk/examples/f77/x30f.fm4 2009-12-02 03:36:24 UTC (rev 10663) @@ -46,7 +46,7 @@ integer i, j integer icol, r, g, b - real*8 a, clevel(101), z(2,2) + real*8 a, clevel(101) character*1 defined @@ -133,31 +133,24 @@ enddo enddo -c The overlaid box is drawn using plshades with a color map that is -c the same color but has a linearly varying transparency. - c Create the color map with 128 colors and call plscmap1la to initialize -c the color values with a linear varying transparency (or alpha) +c the color values with a linearly varying red transparency (or alpha) call plscmap1n(128) call plscmap1la(1, 2, pos, rcoord, gcoord, bcoord, acoord, rev) -c Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will -c used for the shade plot. plshades uses linear interpolation to -c calculate the z values of all the intermediate points in this array. - z(1,1) = 0.0d0 - z(2,1) = 0.0d0 - z(1,2) = 1.0d0 - z(2,2) = 1.0d0 +c Use that cmap1 to create a transparent red gradient for the whole +c window. + px(1) = 0.d0 + px(2) = 1.d0 + px(3) = 1.d0 + px(4) = 0.d0 -c Set the color levels array. These levels are also between 0.0 and 1.0 - do i = 1,101 - clevel(i) = 0.01d0 * dble(i-1) - enddo + py(1) = 0.d0 + py(2) = 0.d0 + py(3) = 1.d0 + py(4) = 1.d0 -c Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y coordinate ranges -c such that it fills the entire plotting area. - call plshades0(z, 2, 2, defined, 0.0d0, 1.0d0, 0.0d0, 1.0d0, - & clevel, 101, 0, -1, 2, 2) + call plgradient( 4, px, py, 90.d0 ) call plend() end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-02 06:42:22
|
Revision: 10665 http://plplot.svn.sourceforge.net/plplot/?rev=10665&view=rev Author: airwin Date: 2009-12-02 06:42:13 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Implement plgradient for f95 bindings and make f95 examples 25 and 30 produce consistent results with their C counterparts (which use plgradient). Modified Paths: -------------- trunk/bindings/f95/plstubs.h trunk/bindings/f95/scstubs.c trunk/bindings/f95/sfstubsf95.f90 trunk/examples/f95/x25f.f90 trunk/examples/f95/x30f.f90 Modified: trunk/bindings/f95/plstubs.h =================================================================== --- trunk/bindings/f95/plstubs.h 2009-12-02 06:40:52 UTC (rev 10664) +++ trunk/bindings/f95/plstubs.h 2009-12-02 06:42:13 UTC (rev 10665) @@ -219,6 +219,7 @@ #define PLGLEVEL FNAME( PLGLEVEL, plglevel ) #define PLGPAGE FNAME( PLGPAGE, plgpage ) #define PLGRA FNAME( PLGRA, plgra ) +#define PLGRADIENT FNAME( PLGRADIENTF77, plgradientf77 ) #define PLGRIDDATA FNAME( PLGRIDDATAF77, plgriddataf77 ) #define PLGSPA FNAME( PLGSPA, plgspa ) #define PLGSTRM FNAME( PLGSTRM, plgstrm ) Modified: trunk/bindings/f95/scstubs.c =================================================================== --- trunk/bindings/f95/scstubs.c 2009-12-02 06:40:52 UTC (rev 10664) +++ trunk/bindings/f95/scstubs.c 2009-12-02 06:42:13 UTC (rev 10665) @@ -372,6 +372,12 @@ c_plgra(); } +void +PLGRADIENT( PLINT *n, PLFLT *x, PLFLT *y, PLFLT *angle ) +{ + c_plgradient( *n, x, y, *angle ); +} + /* AM - removed: also defined, and better in sccont.c * void * PLGRIDDATA(PLFLT *x, PLFLT *y, PLFLT *z, PLINT *npts, Modified: trunk/bindings/f95/sfstubsf95.f90 =================================================================== --- trunk/bindings/f95/sfstubsf95.f90 2009-12-02 06:40:52 UTC (rev 10664) +++ trunk/bindings/f95/sfstubsf95.f90 2009-12-02 06:42:13 UTC (rev 10665) @@ -401,6 +401,10 @@ end subroutine plgra end interface + interface plgradient + module procedure plgradient + end interface + interface plgriddata module procedure plgriddata end interface @@ -1009,6 +1013,13 @@ call plfill3f77( size(x), x, y, z ) end subroutine plfill3 + subroutine plgradient( x, y, angle ) + real(kind=plflt), dimension(:) :: x, y + real(kind=plflt) :: angle + + call plgradientf77( size(x), x, y, angle ) + end subroutine plgradient + subroutine plgriddata( x, y, z, xg, yg, zg, type, data ) real(kind=plflt), dimension(:) :: x, y, z, xg, yg real(kind=plflt), dimension(:,:) :: zg Modified: trunk/examples/f95/x25f.f90 =================================================================== --- trunk/examples/f95/x25f.f90 2009-12-02 06:40:52 UTC (rev 10664) +++ trunk/examples/f95/x25f.f90 2009-12-02 06:42:13 UTC (rev 10665) @@ -1,4 +1,4 @@ -! $Id:$ +! $Id$ ! ! Filling and clipping polygons. ! @@ -33,8 +33,7 @@ use plplot implicit none - integer i - integer j + integer i, j, k integer npts real(kind=plflt) xextreme(2,10) real(kind=plflt) yextreme(2,10) @@ -46,15 +45,15 @@ -120.0_plflt, 120.0_plflt, -120.0_plflt, 120.0_plflt, & -120.0_plflt, 120.0_plflt, 20.0_plflt, 120.0_plflt, & -120.0_plflt, 120.0_plflt, -20.0_plflt, 120.0_plflt, & - -80.0_plflt, 80.0_plflt, -20.0_plflt, 120.0_plflt, & + -80.0_plflt, 80.0_plflt, -20.0_plflt, 120.0_plflt, & -220.0_plflt, -120.0_plflt, -120.0_plflt, 120.0_plflt, & - -20.0_plflt, 20.0_plflt, -120.0_plflt, 120.0_plflt, & - -20.0_plflt, 20.0_plflt, -20.0_plflt, 20.0_plflt, & - -80.0_plflt, 80.0_plflt, -80.0_plflt, 80.0_plflt, & - 20.0_plflt, 120.0_plflt, -120.0_plflt, 120.0_plflt/ + -20.0_plflt, 20.0_plflt, -120.0_plflt, 120.0_plflt, & + -20.0_plflt, 20.0_plflt, -20.0_plflt, 20.0_plflt, & + -80.0_plflt, 80.0_plflt, -80.0_plflt, 80.0_plflt, & + 20.0_plflt, 120.0_plflt, -120.0_plflt, 120.0_plflt/ npts = 0 - + ! Parse and process command line arguments call plparseopts(PL_PARSE_FULL) @@ -64,99 +63,105 @@ call plssub(3,3) call plinit() - do j = 1,4 + do k = 1,2 + do j = 1,4 - if ( j .eq. 1 ) then - ! Polygon 1: a diamond - x0(1) = 0.0_plflt - y0(1) = -100.0_plflt - x0(2) = -100.0_plflt - y0(2) = 0.0_plflt - x0(3) = 0.0_plflt - y0(3) = 100.0_plflt - x0(4) = 100.0_plflt - y0(4) = 0.0_plflt - npts = 4 - endif - if ( j .eq. 2 ) then - ! Polygon 1: a diamond - reverse direction - x0(4) = 0.0_plflt - y0(4) = -100.0_plflt - x0(3) = -100.0_plflt - y0(3) = 0.0_plflt - x0(2) = 0.0_plflt - y0(2) = 100.0_plflt - x0(1) = 100.0_plflt - y0(1) = 0.0_plflt - npts = 4 - endif - if ( j .eq. 3 ) then - ! Polygon 2: a square with punctures - x0(1) = -100.0_plflt - y0(1) = -100.0_plflt - x0(2) = -100.0_plflt - y0(2) = -80.0_plflt - x0(3) = 80.0_plflt - y0(3) = 0.0_plflt - x0(4) = -100.0_plflt - y0(4) = 80.0_plflt - x0(5) = -100.0_plflt - y0(5) = 100.0_plflt - x0(6) = -80.0_plflt - y0(6) = 100.0_plflt - x0(7) = 0.0_plflt - y0(7) = 80.0_plflt - x0(8) = 80.0_plflt - y0(8) = 100.0_plflt - x0(9) = 100.0_plflt - y0(9) = 100.0_plflt - x0(10) = 100.0_plflt - y0(10) = -100.0_plflt - npts = 10 - endif - if ( j .eq. 4 ) then - ! Polygon 2: a square with punctures - reversed direction - x0(10) = -100.0_plflt - y0(10) = -100.0_plflt - x0(9) = -100.0_plflt - y0(9) = -80.0_plflt - x0(8) = 80.0_plflt - y0(8) = 0.0_plflt - x0(7) = -100.0_plflt - y0(7) = 80.0_plflt - x0(6) = -100.0_plflt - y0(6) = 100.0_plflt - x0(5) = -80.0_plflt - y0(5) = 100.0_plflt - x0(4) = 0.0_plflt - y0(4) = 80.0_plflt - x0(3) = 80.0_plflt - y0(3) = 100.0_plflt - x0(2) = 100.0_plflt - y0(2) = 100.0_plflt - x0(1) = 100.0_plflt - y0(1) = -100.0_plflt - npts = 10 - endif + if ( j .eq. 1 ) then + ! Polygon 1: a diamond + x0(1) = 0.0_plflt + y0(1) = -100.0_plflt + x0(2) = -100.0_plflt + y0(2) = 0.0_plflt + x0(3) = 0.0_plflt + y0(3) = 100.0_plflt + x0(4) = 100.0_plflt + y0(4) = 0.0_plflt + npts = 4 + endif + if ( j .eq. 2 ) then + ! Polygon 1: a diamond - reverse direction + x0(4) = 0.0_plflt + y0(4) = -100.0_plflt + x0(3) = -100.0_plflt + y0(3) = 0.0_plflt + x0(2) = 0.0_plflt + y0(2) = 100.0_plflt + x0(1) = 100.0_plflt + y0(1) = 0.0_plflt + npts = 4 + endif + if ( j .eq. 3 ) then + ! Polygon 2: a square with punctures + x0(1) = -100.0_plflt + y0(1) = -100.0_plflt + x0(2) = -100.0_plflt + y0(2) = -80.0_plflt + x0(3) = 80.0_plflt + y0(3) = 0.0_plflt + x0(4) = -100.0_plflt + y0(4) = 80.0_plflt + x0(5) = -100.0_plflt + y0(5) = 100.0_plflt + x0(6) = -80.0_plflt + y0(6) = 100.0_plflt + x0(7) = 0.0_plflt + y0(7) = 80.0_plflt + x0(8) = 80.0_plflt + y0(8) = 100.0_plflt + x0(9) = 100.0_plflt + y0(9) = 100.0_plflt + x0(10) = 100.0_plflt + y0(10) = -100.0_plflt + npts = 10 + endif + if ( j .eq. 4 ) then + ! Polygon 2: a square with punctures - reversed direction + x0(10) = -100.0_plflt + y0(10) = -100.0_plflt + x0(9) = -100.0_plflt + y0(9) = -80.0_plflt + x0(8) = 80.0_plflt + y0(8) = 0.0_plflt + x0(7) = -100.0_plflt + y0(7) = 80.0_plflt + x0(6) = -100.0_plflt + y0(6) = 100.0_plflt + x0(5) = -80.0_plflt + y0(5) = 100.0_plflt + x0(4) = 0.0_plflt + y0(4) = 80.0_plflt + x0(3) = 80.0_plflt + y0(3) = 100.0_plflt + x0(2) = 100.0_plflt + y0(2) = 100.0_plflt + x0(1) = 100.0_plflt + y0(1) = -100.0_plflt + npts = 10 + endif - do i = 1,9 - call pladv(0) - call plvsta() - call plwind(xextreme(1,i), xextreme(2,i), & - yextreme(1,i), yextreme(2,i)) + do i = 1,9 + call pladv(0) + call plvsta() + call plwind(xextreme(1,i), xextreme(2,i), & + yextreme(1,i), yextreme(2,i)) - call plcol0(2) - call plbox('bc', 1.0d0, 0, 'bcnv', 10.0d0, 0) - call plcol0(1) - call plpsty(0) - call plfill(x0(1:npts),y0(1:npts)) - call plcol0(2) - call pllsty(1) - call plline(x0(1:npts),y0(1:npts)) + call plcol0(2) + call plbox('bc', 1.0d0, 0, 'bcnv', 10.0d0, 0) + call plcol0(1) + call plpsty(0) + if(k.eq.1) then + call plfill(x0(1:npts),y0(1:npts)) + else + call plgradient(x0(1:npts),y0(1:npts),45.d0) + endif + call plcol0(2) + call pllsty(1) + call plline(x0(1:npts),y0(1:npts)) + end do end do end do ! Don't forget to call plend() to finish off! - + call plend() end program x25f Modified: trunk/examples/f95/x30f.f90 =================================================================== --- trunk/examples/f95/x30f.f90 2009-12-02 06:40:52 UTC (rev 10664) +++ trunk/examples/f95/x30f.f90 2009-12-02 06:42:13 UTC (rev 10665) @@ -22,142 +22,134 @@ ! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ! - program x30f95 - use plplot +program x30f95 + use plplot - implicit none + implicit none - integer, dimension(4) :: red, green, blue - real(kind=plflt), dimension (4) :: alpha, px, py - real(kind=plflt), dimension (2) :: pos, rcoord, gcoord, bcoord, acoord - logical, dimension(2) :: rev + integer, dimension(4) :: red, green, blue + real(kind=plflt), dimension (4) :: alpha, px, py + real(kind=plflt), dimension (2) :: pos, rcoord, gcoord, bcoord, acoord + logical, dimension(2) :: rev - data red / 0, 255, 0, 0 / - data green / 0, 0, 255, 0 / - data blue / 0, 0, 0, 255 / - data alpha / 1.0_plflt, 1.0_plflt, 1.0_plflt, 1.0_plflt / - data px / 0.1_plflt, 0.5_plflt, 0.5_plflt, 0.1_plflt / - data py / 0.1_plflt, 0.1_plflt, 0.5_plflt, 0.5_plflt / - data pos / 0.0_plflt, 1.0_plflt / - data rcoord / 1.0_plflt, 1.0_plflt / - data gcoord / 0.0_plflt, 0.0_plflt / - data bcoord / 0.0_plflt, 0.0_plflt / - data acoord / 0.0_plflt, 1.0_plflt / - data rev / .false. , .false. / + data red / 0, 255, 0, 0 / + data green / 0, 0, 255, 0 / + data blue / 0, 0, 0, 255 / + data alpha / 1.0_plflt, 1.0_plflt, 1.0_plflt, 1.0_plflt / + data px / 0.1_plflt, 0.5_plflt, 0.5_plflt, 0.1_plflt / + data py / 0.1_plflt, 0.1_plflt, 0.5_plflt, 0.5_plflt / + data pos / 0.0_plflt, 1.0_plflt / + data rcoord / 1.0_plflt, 1.0_plflt / + data gcoord / 0.0_plflt, 0.0_plflt / + data bcoord / 0.0_plflt, 0.0_plflt / + data acoord / 0.0_plflt, 1.0_plflt / + data rev / .false. , .false. / - integer i, j - integer icol, r, g, b - real(kind=plflt) :: a, clevel(101), z(2,2) + integer i, j + integer icol, r, g, b + real(kind=plflt) :: a - character*1 defined + character*1 defined - call plparseopts(PL_PARSE_FULL) - - call plinit() + call plparseopts(PL_PARSE_FULL) - call plscmap0n(4) + call plinit() - call plscmap0a (red, green, blue, alpha) + call plscmap0n(4) - ! - ! Page 1: - ! - ! This is a series of red, green and blue rectangles overlaid - ! on each other with gradually increasing transparency. - ! + call plscmap0a (red, green, blue, alpha) - ! Set up the window - call pladv (0) - call plvpor (0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt) - call plwind (0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt) - call plcol0 (0) - call plbox ("", 1.0_plflt, 0, "", 1.0_plflt, 0) - - ! Draw the boxes - do i = 1,9 - icol = mod(i-1,3) + 1 - - ! Get a color, change its transparency and - ! set it as the current color. - call plgcol0a (icol, r, g, b, a) - call plscol0a (icol, r, g, b, 1.0_plflt - dble(i-1)/9.0_plflt) - call plcol0 (icol) - - ! Draw the rectangle - call plfill (px, py) + ! + ! Page 1: + ! + ! This is a series of red, green and blue rectangles overlaid + ! on each other with gradually increasing transparency. + ! - ! Shift the rectangles coordinates - do j = 1,4 - px(j) = px(j) + 0.5_plflt/9.0_plflt - py(j) = py(j) + 0.5_plflt/9.0_plflt - enddo - enddo - ! - ! Page 2: - ! - ! This is a bunch of boxes colored red, green or blue with a single - ! large (red) box of linearly varying transparency overlaid. The - ! overlaid box is completely transparent at the bottom and completely - ! opaque at the top. - ! + ! Set up the window + call pladv (0) + call plvpor (0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt) + call plwind (0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt) + call plcol0 (0) + call plbox ("", 1.0_plflt, 0, "", 1.0_plflt, 0) - ! Set up the window - call pladv(0) - call plvpor(0.1_plflt, 0.9_plflt, 0.1_plflt, 0.9_plflt) - call plwind(0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt) + ! Draw the boxes + do i = 1,9 + icol = mod(i-1,3) + 1 - ! Draw the boxes. There are 25 of them drawn on a 5 x 5 grid. - do i = 1,5 - ! Set box X position - px(1) = 0.05_plflt + 0.2_plflt * dble(i-1) - px(2) = px(1) + 0.1_plflt - px(3) = px(2) - px(4) = px(1) - - ! We don't want the boxes to be transparent, so since we changed - ! the colors transparencies in the first example we have to change - ! the transparencies back to completely opaque. - icol = mod(i-1,3) + 1 - call plgcol0a (icol, r, g, b, a) - call plscol0a (icol, r, g, b, 1.0_plflt) - call plcol0 (icol) - do j = 1, 5 - ! Set box y position and draw the box. - py(1) = 0.05_plflt + 0.2_plflt * dble(j-1) - py(2) = py(1) - py(3) = py(1) + 0.1_plflt - py(4) = py(3) - call plfill(px, py) - enddo - enddo - - ! The overlaid box is drawn using plshades with a color map that is - ! the same color but has a linearly varying transparency. + ! Get a color, change its transparency and + ! set it as the current color. + call plgcol0a (icol, r, g, b, a) + call plscol0a (icol, r, g, b, 1.0_plflt - dble(i-1)/9.0_plflt) + call plcol0 (icol) - ! Create the color map with 128 colors and call plscmap1la to initialize - ! the color values with a linear varying transparency (or alpha) - call plscmap1n(128) - call plscmap1la(.true., pos, rcoord, gcoord, bcoord, acoord, rev) - - ! Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will - ! used for the shade plot. plshades uses linear interpolation to - ! calculate the z values of all the intermediate points in this array. - z(1,1) = 0.0_plflt - z(2,1) = 0.0_plflt - z(1,2) = 1.0_plflt - z(2,2) = 1.0_plflt + ! Draw the rectangle + call plfill (px, py) - ! Set the color levels array. These levels are also between 0.0 and 1.0 - do i = 1,101 - clevel(i) = 0.01_plflt * dble(i-1) - enddo + ! Shift the rectangles coordinates + do j = 1,4 + px(j) = px(j) + 0.5_plflt/9.0_plflt + py(j) = py(j) + 0.5_plflt/9.0_plflt + enddo + enddo + ! + ! Page 2: + ! + ! This is a bunch of boxes colored red, green or blue with a single + ! large (red) box of linearly varying transparency overlaid. The + ! overlaid box is completely transparent at the bottom and completely + ! opaque at the top. + ! - ! Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y coordinate ranges - ! such that it fills the entire plotting area. - call plshades(z, defined, 0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt, & - clevel, 0, -1, 2) + ! Set up the window + call pladv(0) + call plvpor(0.1_plflt, 0.9_plflt, 0.1_plflt, 0.9_plflt) + call plwind(0.0_plflt, 1.0_plflt, 0.0_plflt, 1.0_plflt) - call plend() + ! Draw the boxes. There are 25 of them drawn on a 5 x 5 grid. + do i = 1,5 + ! Set box X position + px(1) = 0.05_plflt + 0.2_plflt * dble(i-1) + px(2) = px(1) + 0.1_plflt + px(3) = px(2) + px(4) = px(1) - end program x30f95 + ! We don't want the boxes to be transparent, so since we changed + ! the colors transparencies in the first example we have to change + ! the transparencies back to completely opaque. + icol = mod(i-1,3) + 1 + call plgcol0a (icol, r, g, b, a) + call plscol0a (icol, r, g, b, 1.0_plflt) + call plcol0 (icol) + do j = 1, 5 + ! Set box y position and draw the box. + py(1) = 0.05_plflt + 0.2_plflt * dble(j-1) + py(2) = py(1) + py(3) = py(1) + 0.1_plflt + py(4) = py(3) + call plfill(px, py) + enddo + enddo + ! Create the color map with 128 colors and call plscmap1la to initialize + ! the color values with a linearly varying red transparency (or alpha) + call plscmap1n(128) + call plscmap1la(.true., pos, rcoord, gcoord, bcoord, acoord, rev) + + ! Use that cmap1 to create a transparent red gradient for the whole + ! window. + px(1) = 0._plflt + px(2) = 1._plflt + px(3) = 1._plflt + px(4) = 0._plflt + + py(1) = 0._plflt + py(2) = 0._plflt + py(3) = 1._plflt + py(4) = 1._plflt + + call plgradient( px, py, 90._plflt ) + call plend() + +end program x30f95 + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-02 07:53:13
|
Revision: 10667 http://plplot.svn.sourceforge.net/plplot/?rev=10667&view=rev Author: airwin Date: 2009-12-02 07:53:05 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Implement plgradient for the java bindings and make java examples 25 and 30 produce consistent results with their C counterparts (which use plgradient). Modified Paths: -------------- trunk/bindings/java/PLStream.java trunk/examples/java/x25.java trunk/examples/java/x30.java Modified: trunk/bindings/java/PLStream.java =================================================================== --- trunk/bindings/java/PLStream.java 2009-12-02 07:51:24 UTC (rev 10666) +++ trunk/bindings/java/PLStream.java 2009-12-02 07:53:05 UTC (rev 10667) @@ -365,6 +365,11 @@ plplotjavac.plgra(); } + public void gradient(double[] x, double[] y, double angle) { + if (set_stream() == -1) return; + plplotjavac.plgradient(x, y, angle); +} + public void griddata(double[] x, double[] y, double[] z, double[] xg, double[] yg, double[][] zg, int type, double data) { if (set_stream() == -1) return; Modified: trunk/examples/java/x25.java =================================================================== --- trunk/examples/java/x25.java 2009-12-02 07:51:24 UTC (rev 10666) +++ trunk/examples/java/x25.java 2009-12-02 07:53:05 UTC (rev 10667) @@ -28,107 +28,111 @@ class x25 { - PLStream pls = new PLStream(); + PLStream pls = new PLStream(); - public x25(String[] args) { - int i; - int j; - double[][] xextreme = new double[10][2]; - double[][] yextreme = new double[10][2]; - double[] x0 = new double[1]; - double[] y0 = new double[1]; + public x25(String[] args) { + int i, j, k; + double[][] xextreme = new double[10][2]; + double[][] yextreme = new double[10][2]; + double[] x0 = new double[1]; + double[] y0 = new double[1]; - /* Parse and process command line arguments */ + /* Parse and process command line arguments */ - pls.parseopts(args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM); + pls.parseopts(args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM); - /* Initialize plplot */ + /* Initialize plplot */ - pls.ssub(3,3); - pls.init(); + pls.ssub(3,3); + pls.init(); - xextreme[0][0] = -120.0 ; xextreme[0][1] = 120.0 ; yextreme[0][0] = -120.0 ; yextreme[0][1] = 120.0 ; - xextreme[1][0] = -120.0 ; xextreme[1][1] = 120.0 ; yextreme[1][0] = 20.0 ; yextreme[1][1] = 120.0 ; - xextreme[2][0] = -120.0 ; xextreme[2][1] = 120.0 ; yextreme[2][0] = -20.0 ; yextreme[2][1] = 120.0 ; - xextreme[3][0] = -80.0 ; xextreme[3][1] = 80.0 ; yextreme[3][0] = -20.0 ; yextreme[3][1] = 120.0 ; - xextreme[4][0] = -220.0 ; xextreme[4][1] = -120.0 ; yextreme[4][0] = -120.0 ; yextreme[4][1] = 120.0 ; - xextreme[5][0] = -20.0 ; xextreme[5][1] = 20.0 ; yextreme[5][0] = -120.0 ; yextreme[5][1] = 120.0 ; - xextreme[6][0] = -20.0 ; xextreme[6][1] = 20.0 ; yextreme[6][0] = -20.0 ; yextreme[6][1] = 20.0 ; - xextreme[7][0] = -80.0 ; xextreme[7][1] = 80.0 ; yextreme[7][0] = -80.0 ; yextreme[7][1] = 80.0 ; - xextreme[8][0] = 20.0 ; xextreme[8][1] = 120.0 ; yextreme[8][0] = -120.0 ; yextreme[8][1] = 120.0 ; + xextreme[0][0] = -120.0 ; xextreme[0][1] = 120.0 ; yextreme[0][0] = -120.0 ; yextreme[0][1] = 120.0 ; + xextreme[1][0] = -120.0 ; xextreme[1][1] = 120.0 ; yextreme[1][0] = 20.0 ; yextreme[1][1] = 120.0 ; + xextreme[2][0] = -120.0 ; xextreme[2][1] = 120.0 ; yextreme[2][0] = -20.0 ; yextreme[2][1] = 120.0 ; + xextreme[3][0] = -80.0 ; xextreme[3][1] = 80.0 ; yextreme[3][0] = -20.0 ; yextreme[3][1] = 120.0 ; + xextreme[4][0] = -220.0 ; xextreme[4][1] = -120.0 ; yextreme[4][0] = -120.0 ; yextreme[4][1] = 120.0 ; + xextreme[5][0] = -20.0 ; xextreme[5][1] = 20.0 ; yextreme[5][0] = -120.0 ; yextreme[5][1] = 120.0 ; + xextreme[6][0] = -20.0 ; xextreme[6][1] = 20.0 ; yextreme[6][0] = -20.0 ; yextreme[6][1] = 20.0 ; + xextreme[7][0] = -80.0 ; xextreme[7][1] = 80.0 ; yextreme[7][0] = -80.0 ; yextreme[7][1] = 80.0 ; + xextreme[8][0] = 20.0 ; xextreme[8][1] = 120.0 ; yextreme[8][0] = -120.0 ; yextreme[8][1] = 120.0 ; - for ( j = 0; j < 4; j ++ ) { - if ( j == 0 ) { - /* Polygon 1: a diamond */ - x0 = new double[4]; - y0 = new double[4]; - x0[0] = 0 ; y0[0] = -100; - x0[1] = -100 ; y0[1] = 0; - x0[2] = 0 ; y0[2] = 100; - x0[3] = 100 ; y0[3] = 0; - } - if ( j == 1 ) { - /* Polygon 1: a diamond - reverse direction */ - x0 = new double[4]; - y0 = new double[4]; - x0[3] = 0 ; y0[3] = -100; - x0[2] = -100 ; y0[2] = 0; - x0[1] = 0 ; y0[1] = 100; - x0[0] = 100 ; y0[0] = 0; - } - if ( j == 2 ) { - /* Polygon 2: a square with punctures */ - x0 = new double[10]; - y0 = new double[10]; - x0[0] = -100 ; y0[0] = -100; - x0[1] = -100 ; y0[1] = -80; - x0[2] = 80 ; y0[2] = 0; - x0[3] = -100 ; y0[3] = 80; - x0[4] = -100 ; y0[4] = 100; - x0[5] = -80 ; y0[5] = 100; - x0[6] = 0 ; y0[6] = 80; - x0[7] = 80 ; y0[7] = 100; - x0[8] = 100 ; y0[8] = 100; - x0[9] = 100 ; y0[9] = -100; - } - if ( j == 3 ) { - /* Polygon 2: a square with punctures - reversed direction */ - x0 = new double[10]; - y0 = new double[10]; - x0[9] = -100 ; y0[9] = -100; - x0[8] = -100 ; y0[8] = -80; - x0[7] = 80 ; y0[7] = 0; - x0[6] = -100 ; y0[6] = 80; - x0[5] = -100 ; y0[5] = 100; - x0[4] = -80 ; y0[4] = 100; - x0[3] = 0 ; y0[3] = 80; - x0[2] = 80 ; y0[2] = 100; - x0[1] = 100 ; y0[1] = 100; - x0[0] = 100 ; y0[0] = -100; - } + for ( k = 0; k < 2; k ++ ) { + for ( j = 0; j < 4; j ++ ) { + if ( j == 0 ) { + /* Polygon 1: a diamond */ + x0 = new double[4]; + y0 = new double[4]; + x0[0] = 0 ; y0[0] = -100; + x0[1] = -100 ; y0[1] = 0; + x0[2] = 0 ; y0[2] = 100; + x0[3] = 100 ; y0[3] = 0; + } + if ( j == 1 ) { + /* Polygon 1: a diamond - reverse direction */ + x0 = new double[4]; + y0 = new double[4]; + x0[3] = 0 ; y0[3] = -100; + x0[2] = -100 ; y0[2] = 0; + x0[1] = 0 ; y0[1] = 100; + x0[0] = 100 ; y0[0] = 0; + } + if ( j == 2 ) { + /* Polygon 2: a square with punctures */ + x0 = new double[10]; + y0 = new double[10]; + x0[0] = -100 ; y0[0] = -100; + x0[1] = -100 ; y0[1] = -80; + x0[2] = 80 ; y0[2] = 0; + x0[3] = -100 ; y0[3] = 80; + x0[4] = -100 ; y0[4] = 100; + x0[5] = -80 ; y0[5] = 100; + x0[6] = 0 ; y0[6] = 80; + x0[7] = 80 ; y0[7] = 100; + x0[8] = 100 ; y0[8] = 100; + x0[9] = 100 ; y0[9] = -100; + } + if ( j == 3 ) { + /* Polygon 2: a square with punctures - reversed direction */ + x0 = new double[10]; + y0 = new double[10]; + x0[9] = -100 ; y0[9] = -100; + x0[8] = -100 ; y0[8] = -80; + x0[7] = 80 ; y0[7] = 0; + x0[6] = -100 ; y0[6] = 80; + x0[5] = -100 ; y0[5] = 100; + x0[4] = -80 ; y0[4] = 100; + x0[3] = 0 ; y0[3] = 80; + x0[2] = 80 ; y0[2] = 100; + x0[1] = 100 ; y0[1] = 100; + x0[0] = 100 ; y0[0] = -100; + } - for ( i = 0; i < 9 ; i ++ ) { - pls.adv(0); - pls.vsta(); - pls.wind(xextreme[i][0], xextreme[i][1], yextreme[i][0], yextreme[i][1]); + for ( i = 0; i < 9 ; i ++ ) { + pls.adv(0); + pls.vsta(); + pls.wind(xextreme[i][0], xextreme[i][1], yextreme[i][0], yextreme[i][1]); - pls.col0(2) ; - pls.box("bc", 1.0, 0, "bcnv", 10.0, 0); - pls.col0(1) ; - pls.psty(0) ; - pls.fill(x0,y0) ; - pls.col0(2) ; - pls.lsty(1) ; - pls.line(x0,y0) ; - } - } + pls.col0(2) ; + pls.box("bc", 1.0, 0, "bcnv", 10.0, 0); + pls.col0(1) ; + pls.psty(0) ; + if ( k == 0) + pls.fill(x0,y0) ; + else + pls.gradient(x0,y0,45.) ; + pls.col0(2) ; + pls.lsty(1) ; + pls.line(x0,y0) ; + } + } + } - pls.end(); + pls.end(); - } + } - public static void main( String[] args ) { - new x25( args ); - } + public static void main( String[] args ) { + new x25( args ); + } } Modified: trunk/examples/java/x30.java =================================================================== --- trunk/examples/java/x30.java 2009-12-02 07:51:24 UTC (rev 10666) +++ trunk/examples/java/x30.java 2009-12-02 07:53:05 UTC (rev 10667) @@ -57,10 +57,6 @@ int[] g = new int[1]; int[] b = new int[1]; double[] a = new double[1]; - double[] clevel = new double[101]; - double[][] z = new double[2][2]; - double[][] xg = new double[2][2]; - double[][] yg = new double[2][2]; pls.parseopts (args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM); @@ -141,41 +137,25 @@ } } - // The overlaid box is drawn using plshades with a color map that is - // the same color but has a linearly varying transparency. - // Create the color map with 128 colors and use plscmap1la to initialize - // the color values with a linear varying transparency (or alpha) + // the color values with a linearly varying red transparency (or alpha) pls.scmap1n(128); pls.scmap1la(true, pos, rcoord, gcoord, bcoord, acoord); - // Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will - // used for the shade plot. plshades will use linear interpolation to - // calculate the z values of all the intermediate points in this array. - z[0][0] = 0.0; - z[1][0] = 0.0; - z[0][1] = 1.0; - z[1][1] = 1.0; + //Use that cmap1 to create a transparent red gradient for the whole + // window. + px[0] = 0.; + px[1] = 1.; + px[2] = 1.; + px[3] = 0.; + + py[0] = 0.; + py[1] = 0.; + py[2] = 1.; + py[3] = 1.; + + pls.gradient( px, py, 90. ); - xg[0][0] = 0.0; - xg[1][0] = 1.0; - xg[0][1] = 0.0; - xg[1][1] = 1.0; - - yg[0][0] = 0.0; - yg[1][0] = 0.0; - yg[0][1] = 1.0; - yg[1][1] = 1.0; - - // Set the color levels array. These levels are also between 0.0 and 1.0 - for(i=0;i<101;i++){ - clevel[i] = 0.01 * (double)i; - } - - // Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y - // coordinate ranges such that it fills the entire plotting area. - pls.shades(z, 0.0, 1.0, 0.0, 1.0, clevel, 0, -1, 2, true, xg, yg ); - pls.end(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-02 08:39:01
|
Revision: 10668 http://plplot.svn.sourceforge.net/plplot/?rev=10668&view=rev Author: airwin Date: 2009-12-02 08:38:49 +0000 (Wed, 02 Dec 2009) Log Message: ----------- Implement plgradient for lua bindings and make lua examples 25 and 30 that _should_ produce consistent results with their C counterparts (which use plgradient). In this case example 25 is consistent (which verifies the lua bindings are fine, but for some unknown reason example 30 is not. Modified Paths: -------------- trunk/bindings/lua/plplotluac.i trunk/examples/lua/x25.lua trunk/examples/lua/x30.lua Modified: trunk/bindings/lua/plplotluac.i =================================================================== --- trunk/bindings/lua/plplotluac.i 2009-12-02 07:53:05 UTC (rev 10667) +++ trunk/bindings/lua/plplotluac.i 2009-12-02 08:38:49 UTC (rev 10668) @@ -1038,6 +1038,7 @@ %rename(glevel) plglevel; %rename(gpage) plgpage; %rename(gra) plgra; +%rename(gradient) plgradient; %rename(griddata) plgriddata; %rename(gspa) plgspa; %rename(gstrm) plgstrm; Modified: trunk/examples/lua/x25.lua =================================================================== --- trunk/examples/lua/x25.lua 2009-12-02 07:53:05 UTC (rev 10667) +++ trunk/examples/lua/x25.lua 2009-12-02 08:38:49 UTC (rev 10668) @@ -48,6 +48,7 @@ yextreme = { { -120, 120 }, { 20, 120 }, { -20, 120 }, { -20, 120 }, { -120, 120 }, { -120, 120 }, { -20, 20 }, { -80, 80 }, { -120, 120 } } +for k = 1, 2 do for j = 1, 4 do if j==1 then -- Polygon 1: a diamond @@ -79,12 +80,17 @@ pl.box("bc", 1, 0, "bcnv", 10, 0) pl.col0(1) pl.psty(0) - pl.fill(x0, y0) + if k==1 then + pl.fill(x0, y0) + else + pl.gradient(x0, y0, 45.) + end pl.col0(2) pl.lsty(1) pl.line(x0, y0) end end +end -- Don't forget to call plend() to finish off! pl.plend() Modified: trunk/examples/lua/x30.lua =================================================================== --- trunk/examples/lua/x30.lua 2009-12-02 07:53:05 UTC (rev 10667) +++ trunk/examples/lua/x30.lua 2009-12-02 08:38:49 UTC (rev 10668) @@ -39,8 +39,6 @@ acoord = { 0, 1 } rev = { 0, 0 } -clevel = {} - pl.parseopts (arg, pl.PL_PARSE_FULL); pl.init() @@ -117,26 +115,23 @@ end end --- The overlaid box is drawn using plshades with a color map that is --- the same color but has a linearly varying transparency. - -- Create the color map with 128 colors and use plscmap1la to initialize --- the color values with a linear varying transparency (or alpha) +-- the color values with a linearly varying red transparency (or alpha) pl.scmap1n(128) pl.scmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev) --- Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will --- used for the shade plot. plshades will use linear interpolation to --- calculate the z values of all the intermediate points in this array. -z = { {0, 1}, {0, 1} } +-- Use that cmap1 to create a transparent red gradient for the whole +-- window. +px[1] = 0. +px[2] = 1. +px[3] = 1. +px[4] = 0. --- Set the color levels array. These levels are also between 0.0 and 1.0 -for i=1, 101 do - clevel[i] = 0.01 * (i-1) -end +py[1] = 0. +py[2] = 0. +py[3] = 1. +py[4] = 1. --- Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y coordinate ranges --- such that it fills the entire plotting area. -pl.shades(z, 0, 1, 0, 1, clevel, 0, -1, 2, 1); +pl.gradient(px, py, 90.) pl.plend() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-03 22:08:01
|
Revision: 10675 http://plplot.svn.sourceforge.net/plplot/?rev=10675&view=rev Author: airwin Date: 2009-12-03 22:07:49 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Implement native driver gradients for remaining qt devices (epsqt/pdfqt, qtwidget, and extqt). Some code cleanup. Modified Paths: -------------- trunk/bindings/qt_gui/plqt.cpp trunk/drivers/qt.cpp trunk/include/qt.h Modified: trunk/bindings/qt_gui/plqt.cpp =================================================================== --- trunk/bindings/qt_gui/plqt.cpp 2009-12-03 21:52:56 UTC (rev 10674) +++ trunk/bindings/qt_gui/plqt.cpp 2009-12-03 22:07:49 UTC (rev 10675) @@ -373,14 +373,15 @@ } void QtPLDriver::setGradient( int x1, int x2, int y1, int y2, - int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ) + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ) { if ( !m_painterP->isActive() || ncol1 < 2 ) return; - int i; - qreal stop_arg; - QGradient linear_gradient; - QGradientStops stops; + int i; + qreal stop_arg; + QLinearGradient linear_gradient; + QGradientStops stops; linear_gradient = QLinearGradient( QPointF((qreal) ( x1 * downscale ), (qreal) ( m_dHeight - y1 * downscale )), @@ -650,6 +651,10 @@ delete i->Data.ColourStruct; break; + case SET_GRADIENT: + delete i->Data.LinearGradient; + break; + default: break; } @@ -783,6 +788,35 @@ // redrawFromLastFlush=true; } +void QtPLWidget::setGradient( int x1, int x2, int y1, int y2, + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ) +{ + int i; + BufferElement el; + qreal stop_arg; + QGradientStops stops; + + el.Element = SET_GRADIENT; + + el.Data.LinearGradient = new QLinearGradient; + *el.Data.LinearGradient = QLinearGradient( + QPointF((qreal) ( x1 * downscale ), (qreal) ( m_dHeight - y1 * downscale )), + QPointF((qreal) ( x2 * downscale ), (qreal) ( m_dHeight - y2 * downscale ))); + for ( i = 0; i < ncol1; i++ ) + { + stop_arg = (qreal) i / (qreal) ( ncol1 - 1 ); + stops << QGradientStop( stop_arg, QColor( r[i], g[i], + b[i], (int) ( alpha[i] * 255 ))); + } + ( *el.Data.LinearGradient ).setStops( stops ); + m_listBuffer.append( el ); + + // No need to ask for a redraw at this point. The gradient only + // affects subsequent items. + //redrawFromLastFlush=true; +} + void QtPLWidget::setBackgroundColor( int r, int g, int b, double alpha ) { BufferElement el; @@ -971,6 +1005,7 @@ QVector<qreal> vect; QRectF rect; + // QPen SolidPen; // // QPen NoPen(Qt::NoPen); @@ -1010,6 +1045,10 @@ p->setBrush( SolidBrush ); break; + case SET_GRADIENT: + p->setBrush( *( i->Data.LinearGradient )); + break; + case LINE: if ( !hasPen ) { Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-12-03 21:52:56 UTC (rev 10674) +++ trunk/drivers/qt.cpp 2009-12-03 22:07:49 UTC (rev 10675) @@ -335,8 +335,8 @@ void plD_esc_rasterqt( PLStream * pls, PLINT op, void* ptr ) { short *xa, *ya; - int *r, *g, *b; - qreal *alpha; + unsigned char *r, *g, *b; + PLFLT *alpha; PLINT i; QtRasterDevice * widget = (QtRasterDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) @@ -373,10 +373,10 @@ case PLESC_GRADIENT: xa = new short[pls->dev_npts]; ya = new short[pls->dev_npts]; - r = new int [pls->ncol1]; - g = new int [pls->ncol1]; - b = new int [pls->ncol1]; - alpha = new qreal [pls->ncol1]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; for ( i = 0; i < pls->ncol1; i++ ) { @@ -385,7 +385,7 @@ b[i] = pls->cmap1[i].b; alpha[i] = pls->cmap1[i].a; } - widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); for ( i = 0; i < pls->dev_npts; i++ ) { @@ -768,11 +768,11 @@ void plD_esc_svgqt( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - int *r, *g, *b; - qreal *alpha; - PLINT i; - QtSVGDevice * widget = (QtSVGDevice *) pls->dev; + short *xa, *ya; + unsigned char *r, *g, *b; + PLFLT *alpha; + PLINT i; + QtSVGDevice * widget = (QtSVGDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) { return; @@ -800,10 +800,10 @@ case PLESC_GRADIENT: xa = new short[pls->dev_npts]; ya = new short[pls->dev_npts]; - r = new int [pls->ncol1]; - g = new int [pls->ncol1]; - b = new int [pls->ncol1]; - alpha = new qreal [pls->ncol1]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; for ( i = 0; i < pls->ncol1; i++ ) { @@ -812,9 +812,8 @@ b[i] = pls->cmap1[i].b; alpha[i] = pls->cmap1[i].a; } - widget->QtPLDriver::setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); - for ( i = 0; i < pls->dev_npts; i++ ) { xa[i] = pls->dev_x[i]; @@ -932,10 +931,11 @@ plParseDrvOpts( qt_options ); /* Stream setup */ - pls->color = 1; - pls->plbuf_write = 0; - pls->dev_fill0 = 1; - pls->dev_fill1 = 0; + pls->color = 1; + pls->plbuf_write = 0; + pls->dev_fill0 = 1; + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -1047,9 +1047,11 @@ void plD_esc_epspdfqt( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - PLINT i; - QtEPSDevice * widget = (QtEPSDevice *) pls->dev; + short *xa, *ya; + unsigned char *r, *g, *b; + PLFLT *alpha; + PLINT i; + QtEPSDevice * widget = (QtEPSDevice *) pls->dev; if ( widget != NULL && qt_family_check( pls )) { return; @@ -1074,6 +1076,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ @@ -1197,10 +1231,11 @@ plP_setpxl( temp.logicalDpiX() / 25.4 / widget->downscale, temp.logicalDpiY() / 25.4 / widget->downscale ); - pls->color = 1; /* Is a color device */ - pls->plbuf_write = 1; /* Store commands to device in core buffer */ - pls->dev_fill0 = 1; /* Handle solid fills */ - pls->dev_fill1 = 0; + pls->color = 1; /* Is a color device */ + pls->plbuf_write = 1; /* Store commands to device in core buffer */ + pls->dev_fill0 = 1; /* Handle solid fills */ + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -1261,9 +1296,11 @@ void plD_esc_qtwidget( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - PLINT i; - QtPLWidget * widget = (QtPLWidget *) pls->dev; + short *xa, *ya; + PLINT i; + unsigned char *r, *g, *b; + PLFLT *alpha; + QtPLWidget * widget = (QtPLWidget *) pls->dev; if ( widget == NULL ) return; switch ( op ) @@ -1285,6 +1322,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: widget->setColor( pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a ); widget->drawText( pls, (EscText *) ptr ); @@ -1383,10 +1452,11 @@ plP_setpxl( temp.logicalDpiX() / 25.4 / widget->downscale, temp.logicalDpiY() / 25.4 / widget->downscale ); - pls->color = 1; /* Is a color device */ - pls->plbuf_write = 0; - pls->dev_fill0 = 1; /* Handle solid fills */ - pls->dev_fill1 = 0; + pls->color = 1; /* Is a color device */ + pls->plbuf_write = 0; + pls->dev_fill0 = 1; /* Handle solid fills */ + pls->dev_fill1 = 0; + pls->dev_gradient = 1; /* driver renders gradient */ /* Let the PLplot core handle dashed lines since * the driver results for this capability have a number of issues. * pls->dev_dash=1; */ @@ -1426,9 +1496,11 @@ void plD_esc_extqt( PLStream * pls, PLINT op, void* ptr ) { - short *xa, *ya; - PLINT i; - QtExtWidget * widget = NULL; + short *xa, *ya; + PLINT i; + unsigned char *r, *g, *b; + PLFLT *alpha; + QtExtWidget * widget = NULL; widget = (QtExtWidget*) pls->dev; switch ( op ) @@ -1449,6 +1521,38 @@ delete[] ya; break; + case PLESC_GRADIENT: + xa = new short[pls->dev_npts]; + ya = new short[pls->dev_npts]; + r = new unsigned char[pls->ncol1]; + g = new unsigned char[pls->ncol1]; + b = new unsigned char[pls->ncol1]; + alpha = new PLFLT[pls->ncol1]; + + for ( i = 0; i < pls->ncol1; i++ ) + { + r[i] = pls->cmap1[i].r; + g[i] = pls->cmap1[i].g; + b[i] = pls->cmap1[i].b; + alpha[i] = pls->cmap1[i].a; + } + widget->setGradient( pls->xgradient[0], pls->xgradient[1], pls->ygradient[0], pls->ygradient[1], r, g, b, alpha, pls->ncol1 ); + + for ( i = 0; i < pls->dev_npts; i++ ) + { + xa[i] = pls->dev_x[i]; + ya[i] = pls->dev_y[i]; + } + widget->drawPolygon( xa, ya, pls->dev_npts ); + + delete[] xa; + delete[] ya; + delete[] r; + delete[] g; + delete[] b; + delete[] alpha; + break; + case PLESC_HAS_TEXT: /*$$ call the generic ProcessString function * ProcessString( pls, (EscText *)ptr ); */ Modified: trunk/include/qt.h =================================================================== --- trunk/include/qt.h 2009-12-03 21:52:56 UTC (rev 10674) +++ trunk/include/qt.h 2009-12-03 22:07:49 UTC (rev 10675) @@ -128,9 +128,10 @@ virtual void drawPolygon( short * x, short * y, PLINT npts ); virtual void drawText( PLStream* pls, EscText* txt ); virtual void setColor( int r, int g, int b, double alpha ); + virtual void setBackgroundColor( int r, int g, int b, double alpha ){} virtual void setGradient( int x1, int x2, int y1, int y2, - int *r, int *g, int *b, qreal *alpha, PLINT ncol1 ); - virtual void setBackgroundColor( int r, int g, int b, double alpha ){} + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ); virtual void setWidth( PLINT w ); // Set pen to draw solid strokes (called after drawing dashed strokes) virtual void setSolid(); @@ -233,6 +234,7 @@ RECTANGLE, SET_WIDTH, SET_COLOUR, + SET_GRADIENT, SET_SMOOTH, TEXT, SET_BG_COLOUR @@ -272,6 +274,7 @@ QLineF * Line; QPolygonF * Polyline; QRectF * Rect; + QLinearGradient * LinearGradient; struct ColourStruct_* ColourStruct; struct TextStruct_ * TextStruct; PLINT intParam; @@ -303,6 +306,9 @@ void drawPolygon( short * x, short * y, PLINT npts ); void setColor( int r, int g, int b, double alpha ); void setBackgroundColor( int r, int g, int b, double alpha ); + void setGradient( int x1, int x2, int y1, int y2, + unsigned char *r, unsigned char *g, + unsigned char *b, PLFLT *alpha, PLINT ncol1 ); void setWidth( PLINT r ); void drawText( PLStream* pls, EscText* txt ); void flush(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-04 08:10:40
|
Revision: 10678 http://plplot.svn.sourceforge.net/plplot/?rev=10678&view=rev Author: airwin Date: 2009-12-04 08:10:31 +0000 (Fri, 04 Dec 2009) Log Message: ----------- Re-create our logo using the new plgradient approach. We no longer need the patch file and production of the logo is a lot simpler as a result of the plgradient command now being available. The svg result is essentially the same as the previous patched result and similarly for the *.jpg result created with the ImageMagick convert app. Modified Paths: -------------- trunk/examples/python/README.logo trunk/examples/python/plplot_logo.py trunk/www/img/plplot_logo.jpg Removed Paths: ------------- trunk/examples/python/svg_760x120_gradient.patch Modified: trunk/examples/python/README.logo =================================================================== --- trunk/examples/python/README.logo 2009-12-04 03:28:56 UTC (rev 10677) +++ trunk/examples/python/README.logo 2009-12-04 08:10:31 UTC (rev 10678) @@ -1,36 +1,18 @@ -N.B. This logo production example is not considered to be one of the -standard examples because it has been excessively fine-tuned, and may -be subject to further fine-tuning (which we do not want to keep propagating -to all the rest of the languages). - To produce an SVG form of the logo with -dev svg (which is the device which -plplot_logo.py has been explicitly tuned for) execute (only in the installed -examples/python directory!) +plplot_logo.py has been explicitly tuned for) execute -./plplot_logo.py -dev svg -o plplot_logo.svg -geometry 760x120 +python/plplot_logo.py -dev svg -o plplot_logo.svg -geometry 760x120 -# Patch to apply native SVG gradient. Since this patch is problematic (see -below) use --dry-run first to make sure it will work. +in either the build tree examples directory (after "make python_examples") +or the install-tree examples directory (after "make install"). -patch --dry-run <svg_760x120_gradient.patch -patch <svg_760x120_gradient.patch - -N.B. This patch is problematic because it depends on the exact command -above and absolutely no changes to the svg.c device-driver code or -libplplotd code or even platform dependent rounding. So in general it -shouldn't be considered a working patch (unless --dry-run says it will -apply, see above). Instead, it should be considered a method of reminding -human editors of the plplot_logo.svg file of the simple changes that are -necessary to apply a native SVG opacity gradient as a background to the -legend of the logo. - -The patched results look great on konqueror, but they are slow to render. -The patched results also look good for display (for the default compensation +The results look great on konqueror, but they are slow to render. +The results also look good for display (for the default compensation for text shifts) and take very little time to render. Partially because of the file-bloating issue discussed on list (lots of graphical objects outside device boundaries that are still included in the -file, the size of the file is 1.8M. (Of course, another reason for this +file), the size of the file is 1.8M. (Of course, another reason for this large file size is there is incredible detail (many triangles) used to represent the surface. @@ -44,7 +26,7 @@ (1) The compressed result can still be quickly rendered with "display". (2) The compressed result makes no difference to the slow konqueror rendering, -but that is konqueror's problem and not ours because of how quicky "display" +but that is konqueror's problem and not ours because of how quickly "display" renders the result. (3) Firefox 2 does not know what to do with the compressed result. For @@ -64,7 +46,7 @@ bandwidth compared to the uncompressed svg file. This convert step also appears to get rid of everything outside the device boundaries. -convert plplot_logo.svg.gz plplot_logo.jpg +convert plplot_logo.svg plplot_logo.jpg The result has a file size of 34K compared to the original jpeg logo (www/img/header.jpg) put together by Werner (with external editor?) which @@ -87,4 +69,4 @@ to represent colour surfaces in PLplot can be made much larger without compromising how good the result looks. -Alan W. Irwin 2008-10-19 +Alan W. Irwin 2008-10-19 (revised 2009-12-04) Modified: trunk/examples/python/plplot_logo.py =================================================================== --- trunk/examples/python/plplot_logo.py 2009-12-04 03:28:56 UTC (rev 10677) +++ trunk/examples/python/plplot_logo.py 2009-12-04 08:10:31 UTC (rev 10678) @@ -121,19 +121,25 @@ x=array([0., 0., x1, x1]) y=array([0., 1., 1., 0.]) plfill(x,y) - # Partially opaque (later to be replaced by gradient) from x1 to x2 - plscol0a(15, 0, 0, 0, 0.3) - plcol0(15) + # Black transparent gradient. + pos = array([0.0, 1.0]) + rcoord = array([0.0, 0.0]) + gcoord = array([0.0, 0.0]) + bcoord = array([0.0, 0.0]) + acoord = array([1.0, 0.0]) + rev = array([0, 0]) + plscmap1n(2) + plscmap1la(1, pos, rcoord, gcoord, bcoord, acoord, rev) x=array([x1, x1, x2, x2]) - plfill(x,y) + plgradient(x,y,0.) # Logo Legend plscol0a(15, 255, 255, 255, 1.0) plcol0(15) x1 = 0.03 - plschr(0., 2.5) + plschr(0., 2.9) plsfont(PL_FCI_SANS, PL_FCI_UPRIGHT, PL_FCI_BOLD) plptex(x1, 0.57, 1.0, 0.0, 0.0, "PLplot") - plschr(0., 1.3) + plschr(0., 1.5) plptex(x1, 0.30, 1.0, 0.0, 0.0, "The ultimate in cross-platform plotting") Deleted: trunk/examples/python/svg_760x120_gradient.patch =================================================================== --- trunk/examples/python/svg_760x120_gradient.patch 2009-12-04 03:28:56 UTC (rev 10677) +++ trunk/examples/python/svg_760x120_gradient.patch 2009-12-04 08:10:31 UTC (rev 10678) @@ -1,28 +0,0 @@ ---- plplot_logo.svg 2008-10-18 23:16:48.000000000 -0700 -+++ plplot_logo_edited.svg 2008-10-18 23:17:25.000000000 -0700 -@@ -64209,13 +64209,18 @@ - fill="#000000" - fill-opacity="1.000000" - points="0.00,0.00 0.00,119.98 76.01,119.98 76.01,0.00 0.00,0.00 0.00,0.00 "/> -- <polyline -- stroke-width="1" -- stroke="#000000" -- stroke-opacity="0.300000" -- fill="#000000" -- fill-opacity="0.300000" -- points="76.01,0.00 76.01,119.98 607.96,119.98 607.96,0.00 76.01,0.00 "/> -+ <g> -+ <defs> -+ <linearGradient id="MyGradient"> -+ <stop offset="0%" stop-color="#000" stop-opacity="1." /> -+ <stop offset="100%" stop-color="#000" stop-opacity="0." /> -+ </linearGradient> -+ </defs> -+ <polyline -+ stroke-width="1" -+ fill="url(#MyGradient)" -+ points="76.01,0.00 76.01,119.98 607.96,119.98 607.96,0.00 76.01,0.00 "/> -+ </g> - <clipPath - id="text-clipping19" - > Modified: trunk/www/img/plplot_logo.jpg =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-05 22:47:53
|
Revision: 10685 http://plplot.svn.sourceforge.net/plplot/?rev=10685&view=rev Author: airwin Date: 2009-12-05 22:47:43 +0000 (Sat, 05 Dec 2009) Log Message: ----------- Put new PLplot affine transformation utility functions into buildable (but not yet run-time tested) state. Modified Paths: -------------- trunk/include/plplotP.h trunk/src/CMakeLists.txt trunk/src/plaffine.c Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-12-05 19:53:52 UTC (rev 10684) +++ trunk/include/plplotP.h 2009-12-05 22:47:43 UTC (rev 10685) @@ -433,6 +433,55 @@ extern "C" { #endif +/* Number of elements in the affine vector representation of the affine + * transformation matrix. */ +#define NAFFINE 6 + +/* Returns affine identity matrix */ + +PLDLLIMPEXP void +plP_affine_identity(PLFLT *affine_vector); + +/* Translate new coordinate system axes relative to the old. */ + +PLDLLIMPEXP void +plP_affine_translate(PLFLT *affine_vector, PLFLT xtranslate, PLFLT ytranslate); + +/* Scale new coordinate system axes relative to the old. */ + +PLDLLIMPEXP void +plP_affine_scale(PLFLT *affine_vector, PLFLT xscale, PLFLT yscale); + +/* Rotate new coordinate system axes relative to the old. + * angle is in degrees.*/ + +PLDLLIMPEXP void +plP_affine_rotate(PLFLT *affine_vector, PLFLT angle ); + +/* Skew new X coordinate axis relative to the old. + * angle is in degrees.*/ + +PLDLLIMPEXP void +plP_affine_xskew(PLFLT *affine_vector, PLFLT angle ); + +/* Skew new Y coordinate axis relative to the old. + * angle is in degrees.*/ + +PLDLLIMPEXP void +plP_affine_yskew(PLFLT *affine_vector, PLFLT angle ); + +/* Multiply two affine transformation matrices to form a third. + * + * A = B * C + * + */ + +PLDLLIMPEXP void +plP_affine_multiply( + PLFLT *affine_vectorA, + const PLFLT *affine_vectorB, + const PLFLT *affine_vectorC ); + /* Determines interval between numeric labels */ void Modified: trunk/src/CMakeLists.txt =================================================================== --- trunk/src/CMakeLists.txt 2009-12-05 19:53:52 UTC (rev 10684) +++ trunk/src/CMakeLists.txt 2009-12-05 22:47:43 UTC (rev 10685) @@ -21,6 +21,7 @@ set(plplot${LIB_TAG}_LIB_SRCS pdfutils.c + plaffine.c plarc.c plargs.c plbox.c @@ -31,8 +32,8 @@ pldeprecated.c pldtik.c plfill.c + plfreetype.c plgradient.c - plfreetype.c plgset.c plhist.c plimage.c Modified: trunk/src/plaffine.c =================================================================== --- trunk/src/plaffine.c 2009-12-05 19:53:52 UTC (rev 10684) +++ trunk/src/plaffine.c 2009-12-05 22:47:43 UTC (rev 10685) @@ -1,6 +1,6 @@ /* $Id$ * - * Affine manipulation routines for PLplot. + * Affine manipulation routines for PLplot. * * Copyright (C) 2009 Alan W. Irwin * @@ -22,7 +22,7 @@ * */ -#include "plcore.h" +#include "plplotP.h" /* For background on these affine functions see SVG specification, e.g., * http://www.w3.org/TR/SVGTiny12/coords.html#EstablishingANewUserSpace. @@ -85,12 +85,12 @@ if(xscale == 0.) { plwarn("plP_affine_scale: attempt to scale X coordinates by zero."); - xscale = 1. + xscale = 1.; } if(yscale == 0.) { plwarn("plP_affine_scale: attempt to scale Y coordinates by zero."); - yscale = 1. + yscale = 1.; } affine_vector[0] = 1./xscale; affine_vector[1] = 0.; @@ -180,4 +180,3 @@ for(i=0;i<NAFFINE;i++) affine_vectorA[i] = result[i]; } - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-06 03:13:58
|
Revision: 10686 http://plplot.svn.sourceforge.net/plplot/?rev=10686&view=rev Author: airwin Date: 2009-12-06 03:13:49 +0000 (Sun, 06 Dec 2009) Log Message: ----------- Style previous changes. Modified Paths: -------------- trunk/include/plplotP.h trunk/src/plaffine.c Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-12-05 22:47:43 UTC (rev 10685) +++ trunk/include/plplotP.h 2009-12-06 03:13:49 UTC (rev 10686) @@ -435,40 +435,40 @@ /* Number of elements in the affine vector representation of the affine * transformation matrix. */ -#define NAFFINE 6 +#define NAFFINE 6 /* Returns affine identity matrix */ PLDLLIMPEXP void -plP_affine_identity(PLFLT *affine_vector); +plP_affine_identity( PLFLT *affine_vector ); /* Translate new coordinate system axes relative to the old. */ PLDLLIMPEXP void -plP_affine_translate(PLFLT *affine_vector, PLFLT xtranslate, PLFLT ytranslate); +plP_affine_translate( PLFLT *affine_vector, PLFLT xtranslate, PLFLT ytranslate ); /* Scale new coordinate system axes relative to the old. */ PLDLLIMPEXP void -plP_affine_scale(PLFLT *affine_vector, PLFLT xscale, PLFLT yscale); +plP_affine_scale( PLFLT *affine_vector, PLFLT xscale, PLFLT yscale ); /* Rotate new coordinate system axes relative to the old. * angle is in degrees.*/ PLDLLIMPEXP void -plP_affine_rotate(PLFLT *affine_vector, PLFLT angle ); +plP_affine_rotate( PLFLT *affine_vector, PLFLT angle ); /* Skew new X coordinate axis relative to the old. * angle is in degrees.*/ PLDLLIMPEXP void -plP_affine_xskew(PLFLT *affine_vector, PLFLT angle ); +plP_affine_xskew( PLFLT *affine_vector, PLFLT angle ); /* Skew new Y coordinate axis relative to the old. * angle is in degrees.*/ PLDLLIMPEXP void -plP_affine_yskew(PLFLT *affine_vector, PLFLT angle ); +plP_affine_yskew( PLFLT *affine_vector, PLFLT angle ); /* Multiply two affine transformation matrices to form a third. * Modified: trunk/src/plaffine.c =================================================================== --- trunk/src/plaffine.c 2009-12-05 22:47:43 UTC (rev 10685) +++ trunk/src/plaffine.c 2009-12-06 03:13:49 UTC (rev 10686) @@ -39,111 +39,111 @@ * new_coord_vector = affine_matrix * old_coordinate vector. * The result is all affine matrices below are the inverses of the SVG * equivalents. - + * * N.B. All PLplot affine functions below return the affine matrix result (in * vector form) as the first argument). It is the calling routine's * responsibility to provide the space for all affine matrix arguments, * i.e., a PLFLT array with a dimension of 6. + * + * /* Returns affine identity matrix */ -/* Returns affine identity matrix */ - void -plP_affine_identity(PLFLT *affine_vector) +plP_affine_identity( PLFLT *affine_vector ) { - affine_vector[0] = 1.; - affine_vector[1] = 0.; - affine_vector[2] = 0.; - affine_vector[3] = 1.; - affine_vector[4] = 0.; - affine_vector[5] = 0.; + affine_vector[0] = 1.; + affine_vector[1] = 0.; + affine_vector[2] = 0.; + affine_vector[3] = 1.; + affine_vector[4] = 0.; + affine_vector[5] = 0.; } /* Translate new coordinate system axes relative to the old. */ void -plP_affine_translate(PLFLT *affine_vector, PLFLT xtranslate, PLFLT ytranslate) +plP_affine_translate( PLFLT *affine_vector, PLFLT xtranslate, PLFLT ytranslate ) { - affine_vector[0] = 1.; - affine_vector[1] = 0.; - affine_vector[2] = 0.; - affine_vector[3] = 1.; - /* If the new coordinate system axis is shifted by xtranslate and ytranslate - * relative to the old, then the actual new coordinates are shifted in - * the opposite direction. */ - affine_vector[4] = -xtranslate; - affine_vector[5] = -ytranslate; + affine_vector[0] = 1.; + affine_vector[1] = 0.; + affine_vector[2] = 0.; + affine_vector[3] = 1.; + /* If the new coordinate system axis is shifted by xtranslate and ytranslate + * relative to the old, then the actual new coordinates are shifted in + * the opposite direction. */ + affine_vector[4] = -xtranslate; + affine_vector[5] = -ytranslate; } /* Scale new coordinate system axes relative to the old. */ void -plP_affine_scale(PLFLT *affine_vector, PLFLT xscale, PLFLT yscale) +plP_affine_scale( PLFLT *affine_vector, PLFLT xscale, PLFLT yscale ) { - /* If the new coordinate system axes are scaled by xscale and yscale - * relative to the old, then the actual new coordinates are scaled - * by the inverses. */ - if(xscale == 0.) - { - plwarn("plP_affine_scale: attempt to scale X coordinates by zero."); - xscale = 1.; - } - if(yscale == 0.) - { - plwarn("plP_affine_scale: attempt to scale Y coordinates by zero."); - yscale = 1.; - } - affine_vector[0] = 1./xscale; - affine_vector[1] = 0.; - affine_vector[2] = 0.; - affine_vector[3] = 1./yscale; - affine_vector[4] = 0.; - affine_vector[5] = 0.; + /* If the new coordinate system axes are scaled by xscale and yscale + * relative to the old, then the actual new coordinates are scaled + * by the inverses. */ + if ( xscale == 0. ) + { + plwarn( "plP_affine_scale: attempt to scale X coordinates by zero." ); + xscale = 1.; + } + if ( yscale == 0. ) + { + plwarn( "plP_affine_scale: attempt to scale Y coordinates by zero." ); + yscale = 1.; + } + affine_vector[0] = 1. / xscale; + affine_vector[1] = 0.; + affine_vector[2] = 0.; + affine_vector[3] = 1. / yscale; + affine_vector[4] = 0.; + affine_vector[5] = 0.; } /* Rotate new coordinate system axes relative to the old. * angle is in degrees.*/ void -plP_affine_rotate(PLFLT *affine_vector, PLFLT angle ) +plP_affine_rotate( PLFLT *affine_vector, PLFLT angle ) { - PLFLT cosangle = cos(PI * angle/180.); - PLFLT sinangle = sin(PI * angle/180.); - affine_vector[0] = cosangle; - affine_vector[1] = -sinangle; - affine_vector[2] = sinangle; - affine_vector[3] = cosangle; - affine_vector[4] = 0.; - affine_vector[5] = 0.; + PLFLT cosangle = cos( PI * angle / 180. ); + PLFLT sinangle = sin( PI * angle / 180. ); + affine_vector[0] = cosangle; + affine_vector[1] = -sinangle; + affine_vector[2] = sinangle; + affine_vector[3] = cosangle; + affine_vector[4] = 0.; + affine_vector[5] = 0.; } /* Skew new X coordinate axis relative to the old. * angle is in degrees.*/ void -plP_affine_xskew(PLFLT *affine_vector, PLFLT angle ) +plP_affine_xskew( PLFLT *affine_vector, PLFLT angle ) { - PLFLT tanangle = tan(PI * angle/180.); - affine_vector[0] = 1.; - affine_vector[1] = 0.; - affine_vector[2] = -tanangle; - affine_vector[3] = 0.; - affine_vector[4] = 0.; - affine_vector[5] = 0.; + PLFLT tanangle = tan( PI * angle / 180. ); + affine_vector[0] = 1.; + affine_vector[1] = 0.; + affine_vector[2] = -tanangle; + affine_vector[3] = 0.; + affine_vector[4] = 0.; + affine_vector[5] = 0.; } /* Skew new Y coordinate axis relative to the old. * angle is in degrees.*/ void -plP_affine_yskew(PLFLT *affine_vector, PLFLT angle ) +plP_affine_yskew( PLFLT *affine_vector, PLFLT angle ) { - PLFLT tanangle = tan(PI * angle/180.); - affine_vector[0] = 1.; - affine_vector[1] = -tanangle; - affine_vector[2] = 0.; - affine_vector[3] = 0.; - affine_vector[4] = 0.; - affine_vector[5] = 0.; + PLFLT tanangle = tan( PI * angle / 180. ); + affine_vector[0] = 1.; + affine_vector[1] = -tanangle; + affine_vector[2] = 0.; + affine_vector[3] = 0.; + affine_vector[4] = 0.; + affine_vector[5] = 0.; } /* Multiply two affine transformation matrices to form a third. @@ -158,25 +158,25 @@ const PLFLT *affine_vectorB, const PLFLT *affine_vectorC ) { - int i; - PLFLT result[NAFFINE]; - /* Multiply two affine matrices stored in affine vector form. */ - result[0] = affine_vectorB[0]*affine_vectorC[0] + - affine_vectorB[2]*affine_vectorC[1]; - result[2] = affine_vectorB[0]*affine_vectorC[2] + - affine_vectorB[2]*affine_vectorC[3]; - result[4] = affine_vectorB[0]*affine_vectorC[4] + - affine_vectorB[2]*affine_vectorC[5] + - affine_vectorB[4]; + int i; + PLFLT result[NAFFINE]; + /* Multiply two affine matrices stored in affine vector form. */ + result[0] = affine_vectorB[0] * affine_vectorC[0] + + affine_vectorB[2] * affine_vectorC[1]; + result[2] = affine_vectorB[0] * affine_vectorC[2] + + affine_vectorB[2] * affine_vectorC[3]; + result[4] = affine_vectorB[0] * affine_vectorC[4] + + affine_vectorB[2] * affine_vectorC[5] + + affine_vectorB[4]; - result[1] = affine_vectorB[1]*affine_vectorC[0] + - affine_vectorB[3]*affine_vectorC[1]; - result[3] = affine_vectorB[1]*affine_vectorC[2] + - affine_vectorB[3]*affine_vectorC[3]; - result[5] = affine_vectorB[1]*affine_vectorC[4] + - affine_vectorB[3]*affine_vectorC[5] + - affine_vectorB[5]; + result[1] = affine_vectorB[1] * affine_vectorC[0] + + affine_vectorB[3] * affine_vectorC[1]; + result[3] = affine_vectorB[1] * affine_vectorC[2] + + affine_vectorB[3] * affine_vectorC[3]; + result[5] = affine_vectorB[1] * affine_vectorC[4] + + affine_vectorB[3] * affine_vectorC[5] + + affine_vectorB[5]; - for(i=0;i<NAFFINE;i++) - affine_vectorA[i] = result[i]; + for ( i = 0; i < NAFFINE; i++ ) + affine_vectorA[i] = result[i]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-06 23:12:55
|
Revision: 10692 http://plplot.svn.sourceforge.net/plplot/?rev=10692&view=rev Author: airwin Date: 2009-12-06 23:12:39 +0000 (Sun, 06 Dec 2009) Log Message: ----------- Use elementary affine transformations to compute xform for plptex3. Modified Paths: -------------- trunk/cmake/modules/python.cmake trunk/src/plsym.c Modified: trunk/cmake/modules/python.cmake =================================================================== --- trunk/cmake/modules/python.cmake 2009-12-06 23:10:50 UTC (rev 10691) +++ trunk/cmake/modules/python.cmake 2009-12-06 23:12:39 UTC (rev 10692) @@ -62,57 +62,69 @@ option(HAVE_NUMPY "Use numpy rather than deprecated Numeric" ON) -if(ENABLE_python AND NOT NUMERIC_INCLUDE_PATH) - if(HAVE_NUMPY) - # First check for new version of numpy (replaces Numeric) - execute_process( - COMMAND - ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.get_include()" - OUTPUT_VARIABLE NUMPY_INCLUDE_PATH - RESULT_VARIABLE NUMPY_ERR - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(NUMPY_ERR) - set(HAVE_NUMPY OFF CACHE BOOL "Use numpy rather than deprecated Numeric" FORCE) - endif(NUMPY_ERR) - endif(HAVE_NUMPY) - if(HAVE_NUMPY) - find_path( - NUMERIC_INCLUDE_PATH - arrayobject.h - ${NUMPY_INCLUDE_PATH}/numpy - ) - if(NUMERIC_INCLUDE_PATH) - set(PYTHON_NUMERIC_NAME numpy CACHE INTERNAL "") - endif(NUMERIC_INCLUDE_PATH) - else(HAVE_NUMPY) - # Check for Python Numeric header in same include path or Numeric - # subdirectory of that path to avoid version mismatch. - find_path( - NUMERIC_INCLUDE_PATH - arrayobject.h - ${PYTHON_INCLUDE_PATH} ${PYTHON_INCLUDE_PATH}/Numeric - ) - if(NUMERIC_INCLUDE_PATH) - set(PYTHON_NUMERIC_NAME Numeric CACHE INTERNAL "") - endif (NUMERIC_INCLUDE_PATH) - endif(HAVE_NUMPY) +if(ENABLE_python) + # NUMERIC_INCLUDE_PATH = path to arrayobject.h for either Numeric or numpy. if(NUMERIC_INCLUDE_PATH) + # PYTHON_INCLUDE_PATH reset by above "find_package(PythonLibs)" so + # must append ${NUMERIC_INCLUDE_PATH} for each rebuild. set( PYTHON_INCLUDE_PATH ${PYTHON_INCLUDE_PATH} ${NUMERIC_INCLUDE_PATH} - CACHE INTERNAL "") + CACHE INTERNAL "" + ) else(NUMERIC_INCLUDE_PATH) if(HAVE_NUMPY) - message(STATUS "WARNING: " - "NumPy header not found. Disabling python bindings") + # First check for new version of numpy (replaces Numeric) + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} -c "import numpy; print numpy.get_include()" + OUTPUT_VARIABLE NUMPY_INCLUDE_PATH + RESULT_VARIABLE NUMPY_ERR + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NUMPY_ERR) + set(HAVE_NUMPY OFF CACHE BOOL "Use numpy rather than deprecated Numeric" FORCE) + endif(NUMPY_ERR) + endif(HAVE_NUMPY) + if(HAVE_NUMPY) + find_path( + NUMERIC_INCLUDE_PATH + arrayobject.h + ${NUMPY_INCLUDE_PATH}/numpy + ) + if(NUMERIC_INCLUDE_PATH) + set(PYTHON_NUMERIC_NAME numpy CACHE INTERNAL "") + endif(NUMERIC_INCLUDE_PATH) else(HAVE_NUMPY) - message(STATUS "WARNING: " - "Numeric header not found. Disabling python bindings") + # Check for Python Numeric header in same include path or Numeric + # subdirectory of that path to avoid version mismatch. + find_path( + NUMERIC_INCLUDE_PATH + arrayobject.h + ${PYTHON_INCLUDE_PATH} ${PYTHON_INCLUDE_PATH}/Numeric + ) + if(NUMERIC_INCLUDE_PATH) + set(PYTHON_NUMERIC_NAME Numeric CACHE INTERNAL "") + endif (NUMERIC_INCLUDE_PATH) endif(HAVE_NUMPY) - set(ENABLE_python OFF CACHE BOOL "Enable Python bindings" FORCE) + if(NUMERIC_INCLUDE_PATH) + set( + PYTHON_INCLUDE_PATH + ${PYTHON_INCLUDE_PATH} ${NUMERIC_INCLUDE_PATH} + CACHE INTERNAL "" + ) + else(NUMERIC_INCLUDE_PATH) + if(HAVE_NUMPY) + message(STATUS "WARNING: " + "NumPy header not found. Disabling python bindings") + else(HAVE_NUMPY) + message(STATUS "WARNING: " + "Numeric header not found. Disabling python bindings") + endif(HAVE_NUMPY) + set(ENABLE_python OFF CACHE BOOL "Enable Python bindings" FORCE) + endif(NUMERIC_INCLUDE_PATH) endif(NUMERIC_INCLUDE_PATH) -endif(ENABLE_python AND NOT NUMERIC_INCLUDE_PATH) +endif(ENABLE_python) if(ENABLE_python AND HAVE_NUMPY) # This numpy installation bug found by Geoff. Modified: trunk/src/plsym.c =================================================================== --- trunk/src/plsym.c 2009-12-06 23:10:50 UTC (rev 10691) +++ trunk/src/plsym.c 2009-12-06 23:12:39 UTC (rev 10692) @@ -1731,7 +1731,7 @@ { PLFLT xpc, ypc, xrefpc, yrefpc, xdpc, ydpc, xspc, yspc, ld, ls, cp, shift; PLFLT x_o, y_o, z_o, x_dx, y_dy, z_dz; - PLFLT theta, phi, stride, xform[4]; + PLFLT theta, phi, stride, xform[6], affineL[6], cosphi; /* check that the plotting environment is set up */ if ( plsc->level < 3 ) @@ -1775,7 +1775,7 @@ { phi = -phi; } - phi = 1.570796 - phi; + phi = 0.5 * PI - phi; } /* Determine how to adjust the "stride" of the text to make it @@ -1806,11 +1806,26 @@ yrefpc = plP_mmpcy( yrefpc ); /* compute the transform */ - xform[0] = cos( theta ) * stride; - xform[1] = cos( theta ) * sin( phi ) - sin( theta ) * cos( phi ); - xform[2] = sin( theta ) * stride; - xform[3] = sin( theta ) * sin( phi ) + cos( theta ) * cos( phi ); - + /* This affine transformation corresponds to transforming from old + * coordinates to new coordinates by rotating axes, y shearing + * or (y skewing), and scaling. + * Comment out the explicit xform calculations because we use + * the affine utilities for that calculation instead. */ + /* + * xform[0] = cos( theta ) * stride; + * xform[1] = cos( theta ) * sin( phi ) - sin( theta ) * cos( phi ); + * xform[2] = sin( theta ) * stride; + * xform[3] = sin( theta ) * sin( phi ) + cos( theta ) * cos( phi ); + */ + plP_affine_rotate( xform, 180. * theta / PI ); + plP_affine_yskew( affineL, -180. * phi / PI ); + plP_affine_multiply( xform, affineL, xform ); + cosphi = cos( phi ); + if ( fabs( cosphi ) > 1.e-300 ) + plP_affine_scale( affineL, 1. / stride, 1. / cosphi ); + else + plP_affine_scale( affineL, 1. / stride, 1.e300 ); + plP_affine_multiply( xform, affineL, xform ); plP_text( 0, just, xform, (PLINT) xpc, (PLINT) ypc, (PLINT) xrefpc, (PLINT) yrefpc, text ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-07 04:42:55
|
Revision: 10693 http://plplot.svn.sourceforge.net/plplot/?rev=10693&view=rev Author: airwin Date: 2009-12-07 04:42:38 +0000 (Mon, 07 Dec 2009) Log Message: ----------- Earlier today I mistakenly committed a local experimental fix for python.cmake that was only suitable for CMake-2.8.0. Replace that experimental and CMake version-dependent fix with one which no longer appends the NUMERIC_INCLUDE_PATH variable (mostly misnamed now since it normally carries the numpy include information) to the PYTHON_INCLUDE_PATH variable. This change should do the right thing since it means we are no longer modifying a variable (PYTHON_INCLUDE_PATH) determined by the CMake module system. There is a difference in how the CMake module system treats that variable between 2.6.x. and 2.8.0 (2.6.x sets it once while 2.8.0 resets it each time CMake is rerun). The current commit isolates us from that change so the result should work both on 2.6.x and 2.8.0. Modified Paths: -------------- trunk/bindings/gnome2/python/CMakeLists.txt trunk/bindings/python/CMakeLists.txt trunk/cmake/modules/python.cmake trunk/cmake/modules/summary.cmake Modified: trunk/bindings/gnome2/python/CMakeLists.txt =================================================================== --- trunk/bindings/gnome2/python/CMakeLists.txt 2009-12-06 23:12:39 UTC (rev 10692) +++ trunk/bindings/gnome2/python/CMakeLists.txt 2009-12-07 04:42:38 UTC (rev 10693) @@ -115,6 +115,7 @@ ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}/include ${PYTHON_INCLUDE_PATH} + ${NUMERIC_INCLUDE_PATH} ) ### Build and install the gcw module Modified: trunk/bindings/python/CMakeLists.txt =================================================================== --- trunk/bindings/python/CMakeLists.txt 2009-12-06 23:12:39 UTC (rev 10692) +++ trunk/bindings/python/CMakeLists.txt 2009-12-07 04:42:38 UTC (rev 10693) @@ -41,6 +41,7 @@ ${CMAKE_CURRENT_BINARY_DIR} ${TCL_INCLUDE_PATH} ${PYTHON_INCLUDE_PATH} + ${NUMERIC_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/bindings/swig-support ) else(ENABLE_tk) @@ -51,6 +52,7 @@ ${CMAKE_BINARY_DIR}/include ${CMAKE_CURRENT_BINARY_DIR} ${PYTHON_INCLUDE_PATH} + ${NUMERIC_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/bindings/swig-support ) endif(ENABLE_tk) Modified: trunk/cmake/modules/python.cmake =================================================================== --- trunk/cmake/modules/python.cmake 2009-12-06 23:12:39 UTC (rev 10692) +++ trunk/cmake/modules/python.cmake 2009-12-07 04:42:38 UTC (rev 10693) @@ -64,15 +64,7 @@ if(ENABLE_python) # NUMERIC_INCLUDE_PATH = path to arrayobject.h for either Numeric or numpy. - if(NUMERIC_INCLUDE_PATH) - # PYTHON_INCLUDE_PATH reset by above "find_package(PythonLibs)" so - # must append ${NUMERIC_INCLUDE_PATH} for each rebuild. - set( - PYTHON_INCLUDE_PATH - ${PYTHON_INCLUDE_PATH} ${NUMERIC_INCLUDE_PATH} - CACHE INTERNAL "" - ) - else(NUMERIC_INCLUDE_PATH) + if(NOT NUMERIC_INCLUDE_PATH) if(HAVE_NUMPY) # First check for new version of numpy (replaces Numeric) execute_process( @@ -86,7 +78,10 @@ set(HAVE_NUMPY OFF CACHE BOOL "Use numpy rather than deprecated Numeric" FORCE) endif(NUMPY_ERR) endif(HAVE_NUMPY) + if(HAVE_NUMPY) + # We use the full path name (including numpy on the end), but + # Double-check that all is well with that choice. find_path( NUMERIC_INCLUDE_PATH arrayobject.h @@ -107,23 +102,19 @@ set(PYTHON_NUMERIC_NAME Numeric CACHE INTERNAL "") endif (NUMERIC_INCLUDE_PATH) endif(HAVE_NUMPY) - if(NUMERIC_INCLUDE_PATH) - set( - PYTHON_INCLUDE_PATH - ${PYTHON_INCLUDE_PATH} ${NUMERIC_INCLUDE_PATH} - CACHE INTERNAL "" - ) - else(NUMERIC_INCLUDE_PATH) - if(HAVE_NUMPY) - message(STATUS "WARNING: " - "NumPy header not found. Disabling python bindings") - else(HAVE_NUMPY) - message(STATUS "WARNING: " - "Numeric header not found. Disabling python bindings") - endif(HAVE_NUMPY) - set(ENABLE_python OFF CACHE BOOL "Enable Python bindings" FORCE) - endif(NUMERIC_INCLUDE_PATH) - endif(NUMERIC_INCLUDE_PATH) + + endif(NOT NUMERIC_INCLUDE_PATH) + + if(NOT NUMERIC_INCLUDE_PATH) + if(HAVE_NUMPY) + message(STATUS "WARNING: " + "NumPy header not found. Disabling python bindings") + else(HAVE_NUMPY) + message(STATUS "WARNING: " + "Numeric header not found. Disabling python bindings") + endif(HAVE_NUMPY) + set(ENABLE_python OFF CACHE BOOL "Enable Python bindings" FORCE) + endif(NOT NUMERIC_INCLUDE_PATH) endif(ENABLE_python) if(ENABLE_python AND HAVE_NUMPY) Modified: trunk/cmake/modules/summary.cmake =================================================================== --- trunk/cmake/modules/summary.cmake 2009-12-06 23:12:39 UTC (rev 10692) +++ trunk/cmake/modules/summary.cmake 2009-12-07 04:42:38 UTC (rev 10693) @@ -88,7 +88,8 @@ "${_output_results} PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE} PYTHON_INCLUDE_PATH: ${PYTHON_INCLUDE_PATH} -PYTHON_LIBRARIES: ${PYTHON_LIBRARIES}") +PYTHON_LIBRARIES: ${PYTHON_LIBRARIES} +NUMERIC_INCLUDE_PATH: ${NUMERIC_INCLUDE_PATH}") endif(ENABLE_python) set( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2009-12-07 21:26:18
|
Revision: 10700 http://plplot.svn.sourceforge.net/plplot/?rev=10700&view=rev Author: andrewross Date: 2009-12-07 21:26:09 +0000 (Mon, 07 Dec 2009) Log Message: ----------- Add octave support for plgradient and update octave examples 25 and 30 to use it. Modified Paths: -------------- trunk/bindings/octave/plplot_octave.h.in trunk/examples/octave/x25c.m trunk/examples/octave/x30c.m Modified: trunk/bindings/octave/plplot_octave.h.in =================================================================== --- trunk/bindings/octave/plplot_octave.h.in 2009-12-07 19:33:00 UTC (rev 10699) +++ trunk/bindings/octave/plplot_octave.h.in 2009-12-07 21:26:09 UTC (rev 10700) @@ -483,6 +483,7 @@ #define plglevel c_plglevel #define plgpage c_plgpage #define plgra c_plgra +#define plgradient c_plgradient #define plgriddata c_plgriddata #define plgspa c_plgspa #define plgstrm c_plgstrm @@ -932,6 +933,10 @@ void c_plgra( void ); //%name plgra +/* Draw gradient in polygon. */ + +void c_plgradient( PLINT n, PLFLT *x, PLFLT *y, PLFLT angle ); //%name plgradient //%input x(n), y(n) + void plgriddata( PLFLT *x, PLFLT *y, PLFLT *z, int npts, PLFLT *xg, int nptsx, PLFLT *yg, int nptsy, PLFLT **zg, int type, PLFLT data ); //%nowrap Modified: trunk/examples/octave/x25c.m =================================================================== --- trunk/examples/octave/x25c.m 2009-12-07 19:33:00 UTC (rev 10699) +++ trunk/examples/octave/x25c.m 2009-12-07 21:26:09 UTC (rev 10700) @@ -26,44 +26,50 @@ xextreme = [-120,120;-120,120;-120,120;-80,80;-220,-120;-20,20;-20,20;-80,80;20,120]; yextreme = [-120,120;20,120;-20,120;-20,120;-120,120;-120,120;-20,20;-80,80;-120,120]; - for j=0:3 - if ( j == 0 ) - ## Polygon 1: a diamond - x0 = [0;-100;0;100]; - y0 = [-100;0;100;0]; - npts = 4 ; - endif - if ( j == 1 ) -## Polygon 1: a diamond - reverse direction - x0 = [100;0;-100;0]; - y0 = [0;100;0;-100]; - npts = 4 ; - endif - if ( j == 2 ) -## Polygon 2: a square with punctures - x0 = [-100;-100;80;-100;-100;-80;0;80;100;100]; - y0 = [-100;-80;0;80;100;100;80;100;100;-100]; - npts = 10 ; - endif - if ( j == 3 ) -## Polygon 2: a square with punctures - reversed direction - x0 = [100;100;80;0;-80;-100;-100;80;-100;-100]; - y0 = [-100;100;100;80;100;100;80;0;-80;-100]; - npts = 10 ; - endif - for i = 1:9 - pladv(0); - plvsta; - plwind(xextreme(i,1), xextreme(i,2), yextreme(i,1), yextreme(i,2)); - - plcol0(2) ; - plbox("bc", 1.0, 0, "bcnv", 10.0, 0); - plcol0(1) ; - plpsty(0) ; - plfill(x0,y0) ; - plcol0(2) ; - pllsty(1) ; - plline(x0,y0) ; + for k=0:1 + for j=0:3 + if ( j == 0 ) + ## Polygon 1: a diamond + x0 = [0;-100;0;100]; + y0 = [-100;0;100;0]; + npts = 4 ; + endif + if ( j == 1 ) + ## Polygon 1: a diamond - reverse direction + x0 = [100;0;-100;0]; + y0 = [0;100;0;-100]; + npts = 4 ; + endif + if ( j == 2 ) + ## Polygon 2: a square with punctures + x0 = [-100;-100;80;-100;-100;-80;0;80;100;100]; + y0 = [-100;-80;0;80;100;100;80;100;100;-100]; + npts = 10 ; + endif + if ( j == 3 ) + ## Polygon 2: a square with punctures - reversed direction + x0 = [100;100;80;0;-80;-100;-100;80;-100;-100]; + y0 = [-100;100;100;80;100;100;80;0;-80;-100]; + npts = 10 ; + endif + for i = 1:9 + pladv(0); + plvsta; + plwind(xextreme(i,1), xextreme(i,2), yextreme(i,1), yextreme(i,2)); + + plcol0(2) ; + plbox("bc", 1.0, 0, "bcnv", 10.0, 0); + plcol0(1) ; + plpsty(0) ; + if (k == 0) + plfill(x0,y0) ; + else + plgradient(x0,y0,45.) ; + endif + plcol0(2) ; + pllsty(1) ; + plline(x0,y0) ; + endfor endfor endfor Modified: trunk/examples/octave/x30c.m =================================================================== --- trunk/examples/octave/x30c.m 2009-12-07 19:33:00 UTC (rev 10699) +++ trunk/examples/octave/x30c.m 2009-12-07 21:26:09 UTC (rev 10700) @@ -130,21 +130,19 @@ plscmap1n(128); plscmap1la(1, pos', rcoord', gcoord', bcoord', acoord', rev'); - ## Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will - ## used for the shade plot. plshades will use linear interpolation to - ## calculate the z values of all the intermediate points in this - ## array. - z = zeros(2,2); - z(1,2) = 1.0; - z(2,2) = 1.0; + ## Use that cmap1 to create a transparent red gradient for the whole + ## window. + px(1) = 0.; + px(2) = 1.; + px(3) = 1.; + px(4) = 0.; - ## Set the color levels array. These levels are also between 0.0 and - ## 1.0 - clevel = 0.01 * (0:100); + py(1) = 0.; + py(2) = 0.; + py(3) = 1.; + py(4) = 1.; - ## Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y - ## coordinate ranges such that it fills the entire plotting area. - plshades(z, 0.0, 1.0, 0.0, 1.0, clevel', 0, -1, 2, 1); + plgradient( px', py', 90. ); plend1(); endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <and...@us...> - 2009-12-07 21:43:00
|
Revision: 10701 http://plplot.svn.sourceforge.net/plplot/?rev=10701&view=rev Author: andrewross Date: 2009-12-07 21:42:50 +0000 (Mon, 07 Dec 2009) Log Message: ----------- Add plgradient to tcl bindings and update examples 25 and 30 to use it. Modified Paths: -------------- trunk/bindings/tcl/plapi.tpl trunk/examples/tcl/x25.tcl trunk/examples/tcl/x30.tcl Modified: trunk/bindings/tcl/plapi.tpl =================================================================== --- trunk/bindings/tcl/plapi.tpl 2009-12-07 21:26:09 UTC (rev 10700) +++ trunk/bindings/tcl/plapi.tpl 2009-12-07 21:42:50 UTC (rev 10701) @@ -382,6 +382,14 @@ pltclcmd plgra void +# Draw gradient in polygon. + +pltclcmd plgradient void +n PLINT +x PLFLT * +y PLFLT * +angle PLFLT + # Get subpage boundaries in absolute coordinates. pltclcmd plgspa void Modified: trunk/examples/tcl/x25.tcl =================================================================== --- trunk/examples/tcl/x25.tcl 2009-12-07 21:26:09 UTC (rev 10700) +++ trunk/examples/tcl/x25.tcl 2009-12-07 21:42:50 UTC (rev 10701) @@ -77,94 +77,100 @@ yextreme 8 0 = -120.0 yextreme 8 1 = 120.0 - for {set j 0} {$j < 4} {incr j} { - if { $j == 0 } { - # Polygon 1: a diamond - x0 0 = 0 - y0 0 = -100 - x0 1 = -100 - y0 1 = 0 - x0 2 = 0 - y0 2 = 100 - x0 3 = 100 - y0 3 = 0 - set npts 4 - } - if { $j == 1 } { - # Polygon 1: a diamond - reverse direction - x0 3 = 0 - y0 3 = -100 - x0 2 = -100 - y0 2 = 0 - x0 1 = 0 - y0 1 = 100 - x0 0 = 100 - y0 0 = 0 - set npts 4 - } - if { $j == 2 } { - # Polygon 2: a square with punctures - x0 0 = -100 - y0 0 = -100 - x0 1 = -100 - y0 1 = -80 - x0 2 = 80 - y0 2 = 0 - x0 3 = -100 - y0 3 = 80 - x0 4 = -100 - y0 4 = 100 - x0 5 = -80 - y0 5 = 100 - x0 6 = 0 - y0 6 = 80 - x0 7 = 80 - y0 7 = 100 - x0 8 = 100 - y0 8 = 100 - x0 9 = 100 - y0 9 = -100 - set npts 10 - } - if { $j == 3 } { - # Polygon 2: a square with punctures - reversed direction - x0 9 = -100 - y0 9 = -100 - x0 8 = -100 - y0 8 = -80 - x0 7 = 80 - y0 7 = 0 - x0 6 = -100 - y0 6 = 80 - x0 5 = -100 - y0 5 = 100 - x0 4 = -80 - y0 4 = 100 - x0 3 = 0 - y0 3 = 80 - x0 2 = 80 - y0 2 = 100 - x0 1 = 100 - y0 1 = 100 - x0 0 = 100 - y0 0 = -100 - set npts 10 - } + for {set k 0} {$k < 2} {incr k} { + for {set j 0} {$j < 4} {incr j} { + if { $j == 0 } { + # Polygon 1: a diamond + x0 0 = 0 + y0 0 = -100 + x0 1 = -100 + y0 1 = 0 + x0 2 = 0 + y0 2 = 100 + x0 3 = 100 + y0 3 = 0 + set npts 4 + } + if { $j == 1 } { + # Polygon 1: a diamond - reverse direction + x0 3 = 0 + y0 3 = -100 + x0 2 = -100 + y0 2 = 0 + x0 1 = 0 + y0 1 = 100 + x0 0 = 100 + y0 0 = 0 + set npts 4 + } + if { $j == 2 } { + # Polygon 2: a square with punctures + x0 0 = -100 + y0 0 = -100 + x0 1 = -100 + y0 1 = -80 + x0 2 = 80 + y0 2 = 0 + x0 3 = -100 + y0 3 = 80 + x0 4 = -100 + y0 4 = 100 + x0 5 = -80 + y0 5 = 100 + x0 6 = 0 + y0 6 = 80 + x0 7 = 80 + y0 7 = 100 + x0 8 = 100 + y0 8 = 100 + x0 9 = 100 + y0 9 = -100 + set npts 10 + } + if { $j == 3 } { + # Polygon 2: a square with punctures - reversed direction + x0 9 = -100 + y0 9 = -100 + x0 8 = -100 + y0 8 = -80 + x0 7 = 80 + y0 7 = 0 + x0 6 = -100 + y0 6 = 80 + x0 5 = -100 + y0 5 = 100 + x0 4 = -80 + y0 4 = 100 + x0 3 = 0 + y0 3 = 80 + x0 2 = 80 + y0 2 = 100 + x0 1 = 100 + y0 1 = 100 + x0 0 = 100 + y0 0 = -100 + set npts 10 + } - for {set i 0} {$i < 9} {incr i} { - $w cmd pladv 0 - $w cmd plvsta - $w cmd plwind [xextreme $i 0] [xextreme $i 1] [yextreme $i 0] [yextreme $i 1] + for {set i 0} {$i < 9} {incr i} { + $w cmd pladv 0 + $w cmd plvsta + $w cmd plwind [xextreme $i 0] [xextreme $i 1] [yextreme $i 0] [yextreme $i 1] - $w cmd plcol0 2 - $w cmd plbox "bc" 1.0 0 "bcnv" 10.0 0 - $w cmd plcol0 1 - $w cmd plpsty 0 - $w cmd plfill $npts x0 y0 - $w cmd plcol0 2 - $w cmd pllsty 1 - $w cmd plline $npts x0 y0 - } + $w cmd plcol0 2 + $w cmd plbox "bc" 1.0 0 "bcnv" 10.0 0 + $w cmd plcol0 1 + $w cmd plpsty 0 + if { $k == 0 } { + $w cmd plfill $npts x0 y0 + } else { + $w cmd plgradient $npts x0 y0 45.0 + } + $w cmd plcol0 2 + $w cmd pllsty 1 + $w cmd plline $npts x0 y0 + } + } } # Restore defaults Modified: trunk/examples/tcl/x30.tcl =================================================================== --- trunk/examples/tcl/x30.tcl 2009-12-07 21:26:09 UTC (rev 10700) +++ trunk/examples/tcl/x30.tcl 2009-12-07 21:42:50 UTC (rev 10701) @@ -126,25 +126,19 @@ $w cmd plscmap1n 128 $w cmd plscmap1la 1 2 pos rcoord gcoord bcoord acoord rev - # Create a 2 x 2 array that contains the z values (0.0 to 1.0) that will - # used for the shade plot. plshades will use linear interpolation to - # calculate the z values of all the intermediate points in this array. - matrix z f 2 2 - z 0 0 = 0.0 - z 1 0 = 0.0 - z 0 1 = 1.0 - z 1 1 = 1.0 + # Use that cmap1 to create a transparent red gradient for the whole + # window. + px 0 = 0. + px 1 = 1. + px 2 = 1. + px 3 = 0. - matrix clevel f 101 + py 0 = 0. + py 1 = 0. + py 2 = 1. + py 3 = 1. - # Set the color levels array. These levels are also between 0.0 and 1.0 - for {set i 0} {$i<101} {incr i} { - clevel $i = [expr {0.01 * double($i)}] - } + $w cmd plgradient 4 px py 90. - # Draw the shade plot with zmin = 0.0, zmax = 1.0 and x and y coordinate ranges - # such that it fills the entire plotting area. - $w cmd plshades z 0.0 1.0 0.0 1.0 clevel 0 -1 2 1 - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-07 22:25:03
|
Revision: 10705 http://plplot.svn.sourceforge.net/plplot/?rev=10705&view=rev Author: airwin Date: 2009-12-07 22:24:51 +0000 (Mon, 07 Dec 2009) Log Message: ----------- Style Java source. Modified Paths: -------------- trunk/bindings/java/PLCallbackLabel.java trunk/bindings/java/PLCallbackMapform.java trunk/bindings/java/PLStream.java trunk/bindings/java/config.java.in trunk/examples/java/x01.java trunk/examples/java/x02.java trunk/examples/java/x03.java trunk/examples/java/x04.java trunk/examples/java/x05.java trunk/examples/java/x06.java trunk/examples/java/x07.java trunk/examples/java/x08.java trunk/examples/java/x09.java trunk/examples/java/x10.java trunk/examples/java/x11.java trunk/examples/java/x12.java trunk/examples/java/x13.java trunk/examples/java/x14.java trunk/examples/java/x15.java trunk/examples/java/x16.java trunk/examples/java/x17.java trunk/examples/java/x18.java trunk/examples/java/x19.java trunk/examples/java/x20.java trunk/examples/java/x21.java trunk/examples/java/x22.java trunk/examples/java/x23.java trunk/examples/java/x24.java trunk/examples/java/x25.java trunk/examples/java/x26.java trunk/examples/java/x27.java trunk/examples/java/x28.java trunk/examples/java/x29.java trunk/examples/java/x30.java trunk/examples/java/x31.java Modified: trunk/bindings/java/PLCallbackLabel.java =================================================================== --- trunk/bindings/java/PLCallbackLabel.java 2009-12-07 22:22:08 UTC (rev 10704) +++ trunk/bindings/java/PLCallbackLabel.java 2009-12-07 22:24:51 UTC (rev 10705) @@ -3,5 +3,5 @@ public interface PLCallbackLabel { - public String label(int axis, double value); + public String label( int axis, double value ); }; Modified: trunk/bindings/java/PLCallbackMapform.java =================================================================== --- trunk/bindings/java/PLCallbackMapform.java 2009-12-07 22:22:08 UTC (rev 10704) +++ trunk/bindings/java/PLCallbackMapform.java 2009-12-07 22:24:51 UTC (rev 10705) @@ -3,5 +3,5 @@ public interface PLCallbackMapform { - public void mapform(double[] x, double[] y); + public void mapform( double[] x, double[] y ); }; Modified: trunk/bindings/java/PLStream.java =================================================================== --- trunk/bindings/java/PLStream.java 2009-12-07 22:22:08 UTC (rev 10704) +++ trunk/bindings/java/PLStream.java 2009-12-07 22:24:51 UTC (rev 10705) @@ -20,8 +20,8 @@ // // This class provides a more object orientated wrapper to the PLplot library // for java. It is currently very similar to the C++ plstream class. -// Each instance of the class corresponds to a plplot stream. Calling a -// method in the class will ensure the stream is correctly set before +// Each instance of the class corresponds to a plplot stream. Calling a +// method in the class will ensure the stream is correctly set before // calling the underlying API function. // @@ -30,356 +30,418 @@ import java.io.*; public class PLStream implements plplotjavacConstants { - // Class data. - int stream_id = -1; + int stream_id = -1; static int active_streams = 0; // Constructor -public PLStream() { - int[] strm = new int[1]; + public PLStream() + { + int[] strm = new int[1]; - // If this is the first instance of the class we - // need to load the C part of the bindings - if (active_streams == 0) { - openlib(); + // If this is the first instance of the class we + // need to load the C part of the bindings + if ( active_streams == 0 ) + { + openlib(); + } + + // Create stream and check it worked ok. + plplotjavac.plmkstrm( strm ); + if ( strm[0] != -1 ) + { + stream_id = strm[0]; + active_streams++; + } + else + { + System.err.println( "Error creating plplot stream" ); + stream_id = -1; + } } - - // Create stream and check it worked ok. - plplotjavac.plmkstrm(strm); - if (strm[0] != -1) { - stream_id = strm[0]; - active_streams++; - } - else { - System.err.println("Error creating plplot stream"); - stream_id = -1; - } -} // Ensure this is the current stream -public int set_stream() { - if ((stream_id == -1) || (active_streams == 0)) { - System.err.println("Error: This stream is not active"); - return -1; + public int set_stream() + { + if (( stream_id == -1 ) || ( active_streams == 0 )) + { + System.err.println( "Error: This stream is not active" ); + return -1; + } + plplotjavac.plsstrm( stream_id ); + return 0; } - plplotjavac.plsstrm(stream_id); - return 0; -} // Method to load the native C part of the java wrapper -public void openlib() { - File libname = null; + public void openlib() + { + File libname = null; - try { - String libdir = System.getProperty("plplot.libdir"); - libname = new File(libdir+File.separatorChar+plplot.core.config.libname); - if (! libname.exists()) { - libname = null; - } - } catch ( Exception e) { - } - if (libname == null) { - libname = new File(plplot.core.config.libdir+File.separatorChar+plplot.core.config.libname); - if ( ! libname.exists() ) { - libname = null; - } - } - if (libname != null) { - try { - System.load( libname.getAbsolutePath() ); - } catch (UnsatisfiedLinkError e) { - System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); - System.exit(1); - } - } - else { - System.err.println("Unable to find native code library.\n"); - System.exit(1); - } + try { + String libdir = System.getProperty( "plplot.libdir" ); + libname = new File( libdir + File.separatorChar + plplot.core.config.libname ); + if ( !libname.exists()) + { + libname = null; + } + } catch ( Exception e ) { + } + if ( libname == null ) + { + libname = new File( plplot.core.config.libdir + File.separatorChar + plplot.core.config.libname ); + if ( !libname.exists()) + { + libname = null; + } + } + if ( libname != null ) + { + try { + System.load( libname.getAbsolutePath()); + } catch ( UnsatisfiedLinkError e ) { + System.err.println( "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e ); + System.exit( 1 ); + } + } + else + { + System.err.println( "Unable to find native code library.\n" ); + System.exit( 1 ); + } + } -} - // The following are wrappers to the C API methods, or their derivatives -public void setcontlabelformat(int lexp, int sigdig) { - if (set_stream() == -1) return; - plplotjavac.pl_setcontlabelformat(lexp, sigdig); -} + public void setcontlabelformat( int lexp, int sigdig ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pl_setcontlabelformat( lexp, sigdig ); + } -public void setcontlabelparam(double offset, double size, double spacing, int active) { - if (set_stream() == -1) return; - plplotjavac.pl_setcontlabelparam(offset, size, spacing, active); -} + public void setcontlabelparam( double offset, double size, double spacing, int active ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pl_setcontlabelparam( offset, size, spacing, active ); + } -public void adv(int page) { - if (set_stream() == -1) return; - plplotjavac.pladv(page); -} + public void adv( int page ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pladv( page ); + } -public void arc(double x, double y, double a, double b, double angle1, double angle2, boolean fill ) { - if (set_stream() == -1) return; - plplotjavac.plarc(x, y, a, b, angle1, angle2, fill); -} + public void arc( double x, double y, double a, double b, double angle1, double angle2, boolean fill ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plarc( x, y, a, b, angle1, angle2, fill ); + } -public void axes(double x0, double y0, String xopt, double xtick, int nxsub, - String yopt, double ytick, int nysub) { - if (set_stream() == -1) return; - plplotjavac.plaxes(x0, y0, xopt, xtick, nxsub, yopt, ytick, nysub); -} + public void axes( double x0, double y0, String xopt, double xtick, int nxsub, + String yopt, double ytick, int nysub ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plaxes( x0, y0, xopt, xtick, nxsub, yopt, ytick, nysub ); + } -public void bin(double[] x, double[] y, int center) { - if (set_stream() == -1) return; - plplotjavac.plbin(x, y, center); -} + public void bin( double[] x, double[] y, int center ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plbin( x, y, center ); + } -public void bop() { - if (set_stream() == -1) return; - plplotjavac.plbop(); -} + public void bop() + { + if ( set_stream() == -1 ) return; + plplotjavac.plbop(); + } -public void box(String xopt, double xtick, int nxsub, - String yopt, double ytick, int nysub) { - if (set_stream() == -1) return; - plplotjavac.plbox(xopt, xtick, nxsub, yopt, ytick, nysub); -} + public void box( String xopt, double xtick, int nxsub, + String yopt, double ytick, int nysub ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plbox( xopt, xtick, nxsub, yopt, ytick, nysub ); + } -public void box3(String xopt, String xlabel, double xtick, int nsubx, - String yopt, String ylabel, double ytick, int nsuby, - String zopt, String zlabel, double ztick, int nsubz) { - if (set_stream() == -1) return; - plplotjavac.plbox3(xopt, xlabel, xtick, nsubx, yopt, ylabel, ytick, nsuby, - zopt, zlabel, ztick, nsubz); -} + public void box3( String xopt, String xlabel, double xtick, int nsubx, + String yopt, String ylabel, double ytick, int nsuby, + String zopt, String zlabel, double ztick, int nsubz ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plbox3( xopt, xlabel, xtick, nsubx, yopt, ylabel, ytick, nsuby, + zopt, zlabel, ztick, nsubz ); + } -public void btime(int year[], int month[], int day[], int hour[], int min[], double sec[], double ctime) { - if (set_stream() == -1) return; - plplotjavac.plbtime(year, month, day, hour, min, sec, ctime); -} + public void btime( int year[], int month[], int day[], int hour[], int min[], double sec[], double ctime ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plbtime( year, month, day, hour, min, sec, ctime ); + } -public void calc_world(double rx, double ry, double[] wx, double[] wy, int[] window) { - if (set_stream() == -1) return; - plplotjavac.plcalc_world(rx, ry, wx, wy, window); -} + public void calc_world( double rx, double ry, double[] wx, double[] wy, int[] window ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plcalc_world( rx, ry, wx, wy, window ); + } -public void clear() { - if (set_stream() == -1) return; - plplotjavac.plclear(); -} + public void clear() + { + if ( set_stream() == -1 ) return; + plplotjavac.plclear(); + } -public void col0(int icol0) { - if (set_stream() == -1) return; - plplotjavac.plcol0(icol0); -} + public void col0( int icol0 ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plcol0( icol0 ); + } -public void col1(double col1) { - if (set_stream() == -1) return; - plplotjavac.plcol1(col1); -} + public void col1( double col1 ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plcol1( col1 ); + } -public void configtime( double scale, double offset1, double offset2, - int ccontrol, boolean ifbtime_offset, int year, - int month, int day, int hour, int min, - double sec) { - if (set_stream() == -1) return; - plplotjavac.plconfigtime(scale, offset1, offset2, ccontrol, ifbtime_offset, - year, month, day, hour, min, sec); -} + public void configtime( double scale, double offset1, double offset2, + int ccontrol, boolean ifbtime_offset, int year, + int month, int day, int hour, int min, + double sec ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plconfigtime( scale, offset1, offset2, ccontrol, ifbtime_offset, + year, month, day, hour, min, sec ); + } -public void cont(double[][] f, int kx, int lx, int ky, int ly, - double[] clevel, double[][] pltr, double[][] OBJECT_DATA) { - if (set_stream() == -1) return; - plplotjavac.plcont(f, kx, lx, ky, ly, clevel, pltr, OBJECT_DATA); -} + public void cont( double[][] f, int kx, int lx, int ky, int ly, + double[] clevel, double[][] pltr, double[][] OBJECT_DATA ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plcont( f, kx, lx, ky, ly, clevel, pltr, OBJECT_DATA ); + } -public void cpstrm(PLStream pls, boolean flags) { - if (set_stream() == -1) return; - plplotjavac.plcpstrm(pls.stream_id, flags); -} + public void cpstrm( PLStream pls, boolean flags ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plcpstrm( pls.stream_id, flags ); + } -public void ctime(int year, int month, int day, int hour, int min, double sec, double ctime[]) { - if (set_stream() == -1) return; - plplotjavac.plctime(year, month, day, hour, min, sec, ctime); -} + public void ctime( int year, int month, int day, int hour, int min, double sec, double ctime[] ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plctime( year, month, day, hour, min, sec, ctime ); + } // The end / end1 functions have extra code in to keep track of the -// stream references in the class. -public void end() { - if (set_stream() == -1) return; - plplotjavac.plend(); - active_streams = 0; - stream_id = -1; -} +// stream references in the class. + public void end() + { + if ( set_stream() == -1 ) return; + plplotjavac.plend(); + active_streams = 0; + stream_id = -1; + } -public void end1() { - if (set_stream() == -1) return; - plplotjavac.plend1(); + public void end1() + { + if ( set_stream() == -1 ) return; + plplotjavac.plend1(); - active_streams--; - stream_id = -1; -} + active_streams--; + stream_id = -1; + } -public void env(double xmin, double xmax, double ymin, double ymax, int just, int axis) { - if (set_stream() == -1) return; - plplotjavac.plenv(xmin, xmax, ymin, ymax, just, axis); -} + public void env( double xmin, double xmax, double ymin, double ymax, int just, int axis ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plenv( xmin, xmax, ymin, ymax, just, axis ); + } -public void env0(double xmin, double xmax, double ymin, double ymax, int just, int axis) { - if (set_stream() == -1) return; - plplotjavac.plenv0(xmin, xmax, ymin, ymax, just, axis); -} + public void env0( double xmin, double xmax, double ymin, double ymax, int just, int axis ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plenv0( xmin, xmax, ymin, ymax, just, axis ); + } -public void eop() { - if (set_stream() == -1) return; - plplotjavac.pleop(); -} + public void eop() + { + if ( set_stream() == -1 ) return; + plplotjavac.pleop(); + } -public void errx(double[] xmin, double[] xmax, double[] y) { - if (set_stream() == -1) return; - plplotjavac.plerrx(xmin, xmax, y); -} + public void errx( double[] xmin, double[] xmax, double[] y ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plerrx( xmin, xmax, y ); + } -public void erry(double[] x, double[] ymin, double[] ymax) { - if (set_stream() == -1) return; - plplotjavac.plerry(x, ymin, ymax); -} + public void erry( double[] x, double[] ymin, double[] ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plerry( x, ymin, ymax ); + } -public void famadv() { - if (set_stream() == -1) return; - plplotjavac.plfamadv(); -} + public void famadv() + { + if ( set_stream() == -1 ) return; + plplotjavac.plfamadv(); + } -public void fill(double[] x, double[] y) { - if (set_stream() == -1) return; - plplotjavac.plfill(x, y); -} + public void fill( double[] x, double[] y ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plfill( x, y ); + } -public void fill3(double[] x, double[] y, double[] z) { - if (set_stream() == -1) return; - plplotjavac.plfill3(x, y, z); -} + public void fill3( double[] x, double[] y, double[] z ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plfill3( x, y, z ); + } -public void flush() { - if (set_stream() == -1) return; - plplotjavac.plflush(); -} + public void flush() + { + if ( set_stream() == -1 ) return; + plplotjavac.plflush(); + } -public void font(int ifont) { - if (set_stream() == -1) return; - plplotjavac.plfont(ifont); -} + public void font( int ifont ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plfont( ifont ); + } -public void fontld(int fnt) { - if (set_stream() == -1) return; - plplotjavac.plfontld(fnt); -} + public void fontld( int fnt ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plfontld( fnt ); + } -public void gchr(double[] p_def, double[] p_ht) { - if (set_stream() == -1) return; - plplotjavac.plgchr(p_def, p_ht); -} + public void gchr( double[] p_def, double[] p_ht ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgchr( p_def, p_ht ); + } -public void gcol0(int icol0, int[] r, int[] g, int[] b) { - if (set_stream() == -1) return; - plplotjavac.plgcol0(icol0, r, g, b); -} + public void gcol0( int icol0, int[] r, int[] g, int[] b ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgcol0( icol0, r, g, b ); + } -public void gcol0a(int icol0, int[] r, int[] g, int[] b, double[] a) { - if (set_stream() == -1) return; - plplotjavac.plgcol0a(icol0, r, g, b, a); -} + public void gcol0a( int icol0, int[] r, int[] g, int[] b, double[] a ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgcol0a( icol0, r, g, b, a ); + } -public void gcolbg(int[] r, int[] g, int[] b) { - if (set_stream() == -1) return; - plplotjavac.plgcolbg(r, g, b); -} + public void gcolbg( int[] r, int[] g, int[] b ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgcolbg( r, g, b ); + } -public void gcolbga(int[] r, int[] g, int[] b, double[] a) { - if (set_stream() == -1) return; - plplotjavac.plgcolbga(r, g, b, a); -} + public void gcolbga( int[] r, int[] g, int[] b, double[] a ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgcolbga( r, g, b, a ); + } -public void gcompression(int[] compression) { - if (set_stream() == -1) return; - plplotjavac.plgcompression(compression); -} + public void gcompression( int[] compression ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgcompression( compression ); + } -public void gdev(StringBuffer dev) { - if (set_stream() == -1) return; - plplotjavac.plgdev(dev); -} + public void gdev( StringBuffer dev ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgdev( dev ); + } -public void gdidev(double[] mar, double[] aspect, double[] jx, double[] jy) { - if (set_stream() == -1) return; - plplotjavac.plgdidev(mar, aspect, jx, jy); -} + public void gdidev( double[] mar, double[] aspect, double[] jx, double[] jy ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgdidev( mar, aspect, jx, jy ); + } -public void gdiori(double[] rot) { - if (set_stream() == -1) return; - plplotjavac.plgdiori(rot); -} + public void gdiori( double[] rot ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgdiori( rot ); + } -public void gdiplt(double[] xmin, double[] xmax, double[] ymin, double[] ymax) { - if (set_stream() == -1) return; - plplotjavac.plgdiplt(xmin, xmax, ymin, ymax); -} + public void gdiplt( double[] xmin, double[] xmax, double[] ymin, double[] ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgdiplt( xmin, xmax, ymin, ymax ); + } -public int getCursor(PLGraphicsIn gin) { - if (set_stream() == -1) return 0; - return plplotjavac.plGetCursor(gin); -} + public int getCursor( PLGraphicsIn gin ) + { + if ( set_stream() == -1 ) return 0; + return plplotjavac.plGetCursor( gin ); + } -public void gfam(int[] fam, int[] num, int[] bmax) { - if (set_stream() == -1) return; - plplotjavac.plgfam(fam, num, bmax); -} + public void gfam( int[] fam, int[] num, int[] bmax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgfam( fam, num, bmax ); + } -public void gfci(long[] pfci) { - if (set_stream() == -1) return; - plplotjavac.plgfci(pfci); -} + public void gfci( long[] pfci ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgfci( pfci ); + } -public void gfnam(StringBuffer fnam) { - if (set_stream() == -1) return; - plplotjavac.plgfnam(fnam); -} + public void gfnam( StringBuffer fnam ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgfnam( fnam ); + } -public void gfont(int[] family, int[] style, int[] weight) { - if (set_stream() == -1) return; - plplotjavac.plgfont(family, style, weight); -} + public void gfont( int[] family, int[] style, int[] weight ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgfont( family, style, weight ); + } -public void glevel(int[] p_level) { - if (set_stream() == -1) return; - plplotjavac.plglevel(p_level); -} + public void glevel( int[] p_level ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plglevel( p_level ); + } -public void gpage(double[] xp, double[] yp, int[] xleng, int[] yleng, int[] xoff, int[] yoff) { - if (set_stream() == -1) return; - plplotjavac.plgpage(xp, yp, xleng, yleng, xoff, yoff); -} + public void gpage( double[] xp, double[] yp, int[] xleng, int[] yleng, int[] xoff, int[] yoff ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgpage( xp, yp, xleng, yleng, xoff, yoff ); + } -public void gra() { - if (set_stream() == -1) return; - plplotjavac.plgra(); -} + public void gra() + { + if ( set_stream() == -1 ) return; + plplotjavac.plgra(); + } - public void gradient(double[] x, double[] y, double angle) { - if (set_stream() == -1) return; - plplotjavac.plgradient(x, y, angle); -} + public void gradient( double[] x, double[] y, double angle ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgradient( x, y, angle ); + } -public void griddata(double[] x, double[] y, double[] z, double[] xg, - double[] yg, double[][] zg, int type, double data) { - if (set_stream() == -1) return; - plplotjavac.plgriddata(x, y, z, xg, yg, zg, type, data); -} + public void griddata( double[] x, double[] y, double[] z, double[] xg, + double[] yg, double[][] zg, int type, double data ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgriddata( x, y, z, xg, yg, zg, type, data ); + } -public void gspa(double[] xmin, double[] xmax, double[] ymin, double[] ymax) { - if (set_stream() == -1) return; - plplotjavac.plgspa(xmin, xmax, ymin, ymax); -} + public void gspa( double[] xmin, double[] xmax, double[] ymin, double[] ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgspa( xmin, xmax, ymin, ymax ); + } // Note: The user should never need this in with this class // since the stream is encapsulated in the class. @@ -388,40 +450,47 @@ // plplotjavac.plgstrm(p_strm); //} -public void gver(StringBuffer ver) { - if (set_stream() == -1) return; - plplotjavac.plgver(ver); -} + public void gver( StringBuffer ver ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgver( ver ); + } -public void gvpd(double[] xmin, double[] xmax, double[] ymin, double[] ymax) { - if (set_stream() == -1) return; - plplotjavac.plgvpd(xmin, xmax, ymin, ymax); -} + public void gvpd( double[] xmin, double[] xmax, double[] ymin, double[] ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgvpd( xmin, xmax, ymin, ymax ); + } -public void gvpw(double[] xmin, double[] xmax, double[] ymin, double[] ymax) { - if (set_stream() == -1) return; - plplotjavac.plgvpw(xmin, xmax, ymin, ymax); -} + public void gvpw( double[] xmin, double[] xmax, double[] ymin, double[] ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgvpw( xmin, xmax, ymin, ymax ); + } -public void gxax(int[] digmax, int[] digits) { - if (set_stream() == -1) return; - plplotjavac.plgxax(digmax, digits); -} + public void gxax( int[] digmax, int[] digits ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgxax( digmax, digits ); + } -public void gyax(int[] digmax, int[] digits) { - if (set_stream() == -1) return; - plplotjavac.plgyax(digmax, digits); -} + public void gyax( int[] digmax, int[] digits ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgyax( digmax, digits ); + } -public void gzax(int[] digmax, int[] digits) { - if (set_stream() == -1) return; - plplotjavac.plgzax(digmax, digits); -} + public void gzax( int[] digmax, int[] digits ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plgzax( digmax, digits ); + } -public void hist(double[] data, double datmin, double datmax, int nbin, int oldwin) { - if (set_stream() == -1) return; - plplotjavac.plhist(data, datmin, datmax, nbin, oldwin); -} + public void hist( double[] data, double datmin, double datmax, int nbin, int oldwin ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plhist( data, datmin, datmax, nbin, oldwin ); + } // Officially deprecated. //public void hls(double h, double l, double s) { @@ -429,76 +498,89 @@ // plplotjavac.plhls(h, l, s); //} -public void image(double[][] data, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double Dxmin, double Dxmax, double Dymin, double Dymax) { - if (set_stream() == -1) return; - plplotjavac.plimage(data, xmin, xmax, ymin, ymax, zmin, zmax, Dxmin, Dxmax, Dymin, Dymax); -} + public void image( double[][] data, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double Dxmin, double Dxmax, double Dymin, double Dymax ) + { + if ( set_stream() == -1 ) return; + 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_im, double[][] OBJECT_DATA_im) { - if (set_stream() == -1) return; - plplotjavac.plimagefr(data, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax, pltr_im, OBJECT_DATA_im); -} + 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_im, OBJECT_DATA_im ); + } -public void init() { - if (set_stream() == -1) return; - plplotjavac.plinit(); -} + public void init() + { + if ( set_stream() == -1 ) return; + plplotjavac.plinit(); + } -public void join(double x1, double y1, double x2, double y2) { - if (set_stream() == -1) return; - plplotjavac.pljoin(x1, y1, x2, y2); -} + public void join( double x1, double y1, double x2, double y2 ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pljoin( x1, y1, x2, y2 ); + } -public void lab(String xlabel, String ylabel, String tlabel) { - if (set_stream() == -1) return; - plplotjavac.pllab(xlabel, ylabel, tlabel); -} + public void lab( String xlabel, String ylabel, String tlabel ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pllab( xlabel, ylabel, tlabel ); + } -public void lightsource(double x, double y, double z) { - if (set_stream() == -1) return; - plplotjavac.pllightsource(x, y, z); -} + public void lightsource( double x, double y, double z ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pllightsource( x, y, z ); + } -public void line(double[] x, double[] y) { - if (set_stream() == -1) return; - plplotjavac.plline(x, y); -} + public void line( double[] x, double[] y ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plline( x, y ); + } -public void line3(double[] x, double[] y, double[] z) { - if (set_stream() == -1) return; - plplotjavac.plline3(x, y, z); -} + public void line3( double[] x, double[] y, double[] z ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plline3( x, y, z ); + } -public void lsty(int lin) { - if (set_stream() == -1) return; - plplotjavac.pllsty(lin); -} + public void lsty( int lin ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pllsty( lin ); + } -public void map(PLCallbackMapform 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 map( PLCallbackMapform 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(PLCallbackMapform 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 meridians( PLCallbackMapform 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); - -} + public void minMax2dGrid( double[][] f, double[] fmax, double[] fmin ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plMinMax2dGrid( f, fmax, fmin ); + } -public void mesh(double[] x, double[] y, double[][] z, int opt) { - if (set_stream() == -1) return; - plplotjavac.plmesh(x, y, z, opt); -} + public void mesh( double[] x, double[] y, double[][] z, int opt ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plmesh( x, y, z, opt ); + } -public void meshc(double[] x, double[] y, double[][] z, int opt, double[] clevel) { - if (set_stream() == -1) return; - plplotjavac.plmeshc(x, y, z, opt,clevel); -} + public void meshc( double[] x, double[] y, double[][] z, int opt, double[] clevel ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plmeshc( x, y, z, opt, clevel ); + } // Don't need this in the OO approach - create a new object instead. //public void mkstrm(int[] OUTPUT) { @@ -506,569 +588,672 @@ // plplotjavac.plmkstrm(int[] OUTPUT); //} -public void mtex(String side, double disp, double pos, double just, String text) { - if (set_stream() == -1) return; - plplotjavac.plmtex(side, disp, pos, just, text); -} + public void mtex( String side, double disp, double pos, double just, String text ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plmtex( side, disp, pos, just, text ); + } -public void mtex3(String side, double disp, double pos, double just, String text) { - if (set_stream() == -1) return; - plplotjavac.plmtex3(side, disp, pos, just, text); -} + public void mtex3( String side, double disp, double pos, double just, String text ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plmtex3( side, disp, pos, just, text ); + } -public void plot3d(double[] x, double[] y, double[][] z, int opt, boolean side) { - if (set_stream() == -1) return; - plplotjavac.plot3d(x, y, z, opt, side); -} + public void plot3d( double[] x, double[] y, double[][] z, int opt, boolean side ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plot3d( x, y, z, opt, side ); + } -public void plot3dc(double[] x, double[] y, double[][] z, int opt, double[] clevel) { - if (set_stream() == -1) return; - plplotjavac.plot3dc(x, y, z, opt, clevel); -} + public void plot3dc( double[] x, double[] y, double[][] z, int opt, double[] clevel ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plot3dc( x, y, z, opt, clevel ); + } -public void plot3dcl(double[] x, double[] y, double[][] z, int opt, - double[] clevel, int ixstart, int[] indexymin, int[] indexymax) { - if (set_stream() == -1) return; - plplotjavac.plot3dcl(x, y, z, opt, clevel, ixstart, indexymin, indexymax); -} + public void plot3dcl( double[] x, double[] y, double[][] z, int opt, + double[] clevel, int ixstart, int[] indexymin, int[] indexymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plot3dcl( x, y, z, opt, clevel, ixstart, indexymin, indexymax ); + } -public void surf3d(double[] x, double[] y, double[][] z, int opt, double[] clevel) { - if (set_stream() == -1) return; - plplotjavac.plsurf3d(x, y, z, opt, clevel); -} + public void surf3d( double[] x, double[] y, double[][] z, int opt, double[] clevel ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsurf3d( x, y, z, opt, clevel ); + } -public void surf3dl(double[] x, double[] y, double[][] z, int opt, - double[] clevel, int ixstart, int[] indexymin, int[] indexymax) { - if (set_stream() == -1) return; - plplotjavac.plsurf3dl(x, y, z, opt, clevel, ixstart, indexymin, indexymax); -} + public void surf3dl( double[] x, double[] y, double[][] z, int opt, + double[] clevel, int ixstart, int[] indexymin, int[] indexymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsurf3dl( x, y, z, opt, clevel, ixstart, indexymin, indexymax ); + } -public void parseopts(String[] argv, int mode) { - if (set_stream() == -1) return; - plplotjavac.plparseopts(argv, mode); -} + public void parseopts( String[] argv, int mode ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plparseopts( argv, mode ); + } -public void pat(int[] inc, int[] del) { - if (set_stream() == -1) return; - plplotjavac.plpat(inc, del); -} + public void pat( int[] inc, int[] del ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plpat( inc, del ); + } -public void poin(double[] x, double[] y, int code) { - if (set_stream() == -1) return; - plplotjavac.plpoin(x, y, code); -} + public void poin( double[] x, double[] y, int code ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plpoin( x, y, code ); + } -public void poin3(double[] x, double[] y, double[] z, int code) { - if (set_stream() == -1) return; - plplotjavac.plpoin3(x, y, z, code); -} + public void poin3( double[] x, double[] y, double[] z, int code ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plpoin3( x, y, z, code ); + } -public void poly3(double[] x, double[] y, double[] z, boolean[] draw, boolean ifcc) { - if (set_stream() == -1) return; - plplotjavac.plpoly3(x, y, z, draw, ifcc); -} + public void poly3( double[] x, double[] y, double[] z, boolean[] draw, boolean ifcc ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plpoly3( x, y, z, draw, ifcc ); + } -public void prec(int setp, int prec) { - if (set_stream() == -1) return; - plplotjavac.plprec(setp, prec); -} + public void prec( int setp, int prec ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plprec( setp, prec ); + } -public void psty(int patt) { - if (set_stream() == -1) return; - plplotjavac.plpsty(patt); -} + public void psty( int patt ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plpsty( patt ); + } -public void ptex(double x, double y, double dx, double dy, double just, String text) { - if (set_stream() == -1) return; - plplotjavac.plptex(x, y, dx, dy, just, text); -} + public void ptex( double x, double y, double dx, double dy, double just, String text ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plptex( x, y, dx, dy, just, text ); + } -public void ptex3(double x, double y, double z, double dx, double dy, double dz, double sx, double sy, double sz, double just, String text) { - if (set_stream() == -1) return; - plplotjavac.plptex3(x, y, z, dx, dy, dz, sx, sy, sz, just, text); -} + public void ptex3( double x, double y, double z, double dx, double dy, double dz, double sx, double sy, double sz, double just, String text ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plptex3( x, y, z, dx, dy, dz, sx, sy, sz, just, text ); + } -public double randd() { - if (set_stream() == -1) return 0.0; - return plplotjavac.plrandd(); -} + public double randd() + { + if ( set_stream() == -1 ) return 0.0; + return plplotjavac.plrandd(); + } -public void replot() { - if (set_stream() == -1) return; - plplotjavac.plreplot(); -} + public void replot() + { + if ( set_stream() == -1 ) return; + plplotjavac.plreplot(); + } -public void schr(double def, double scale) { - if (set_stream() == -1) return; - plplotjavac.plschr(def, scale); -} + public void schr( double def, double scale ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plschr( def, scale ); + } -public void scmap0(int[] r, int[] g, int[] b) { - if (set_stream() == -1) return; - plplotjavac.plscmap0(r, g, b); -} + public void scmap0( int[] r, int[] g, int[] b ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap0( r, g, b ); + } -public void scmap0a(int[] r, int[] g, int[] b, double[] a) { - if (set_stream() == -1) return; - plplotjavac.plscmap0a(r, g, b, a); -} + public void scmap0a( int[] r, int[] g, int[] b, double[] a ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap0a( r, g, b, a ); + } -public void scmap0n(int ncol0) { - if (set_stream() == -1) return; - plplotjavac.plscmap0n(ncol0); -} + public void scmap0n( int ncol0 ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap0n( ncol0 ); + } -public void scmap1(int[] r, int[] g, int[] b) { - if (set_stream() == -1) return; - plplotjavac.plscmap1(r, g, b); -} + public void scmap1( int[] r, int[] g, int[] b ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap1( r, g, b ); + } -public void scmap1a(int[] r, int[] g, int[] b, double[] a) { - if (set_stream() == -1) return; - plplotjavac.plscmap1a(r, g, b, a); -} + public void scmap1a( int[] r, int[] g, int[] b, double[] a ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap1a( r, g, b, a ); + } -public void scmap1l(boolean itype, double[] intensity, double[] coord1, - double[] coord2, double[] coord3, boolean[] rev) { - if (set_stream() == -1) return; - plplotjavac.plscmap1l(itype, intensity, coord1, coord2, coord3, rev); -} + public void scmap1l( boolean itype, double[] intensity, double[] coord1, + double[] coord2, double[] coord3, boolean[] rev ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap1l( itype, intensity, coord1, coord2, coord3, rev ); + } -public void scmap1l(boolean itype, double[] intensity, double[] coord1, - double[] coord2, double[] coord3) { - if (set_stream() == -1) return; - plplotjavac.plscmap1l(itype, intensity, coord1, coord2, coord3, null); -} + public void scmap1l( boolean itype, double[] intensity, double[] coord1, + double[] coord2, double[] coord3 ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap1l( itype, intensity, coord1, coord2, coord3, null ); + } -public void scmap1la(boolean itype, double[] intensity, double[] coord1, - double[] coord2, double[] coord3, double[] a, boolean[] rev) { - if (set_stream() == -1) return; - plplotjavac.plscmap1la(itype, intensity, coord1, coord2, coord3, a, rev); -} + public void scmap1la( boolean itype, double[] intensity, double[] coord1, + double[] coord2, double[] coord3, double[] a, boolean[] rev ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap1la( itype, intensity, coord1, coord2, coord3, a, rev ); + } -public void scmap1la(boolean itype, double[] intensity, double[] coord1, - double[] coord2, double[] coord3, double[] a) { - if (set_stream() == -1) return; - plplotjavac.plscmap1la(itype, intensity, coord1, coord2, coord3, a, null); -} + public void scmap1la( boolean itype, double[] intensity, double[] coord1, + double[] coord2, double[] coord3, double[] a ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap1la( itype, intensity, coord1, coord2, coord3, a, null ); + } -public void scmap1n(int ncol1) { - if (set_stream() == -1) return; - plplotjavac.plscmap1n(ncol1); -} + public void scmap1n( int ncol1 ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscmap1n( ncol1 ); + } -public void scol0(int icol0, int r, int g, int b) { - if (set_stream() == -1) return; - plplotjavac.plscol0(icol0, r, g, b); -} + public void scol0( int icol0, int r, int g, int b ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscol0( icol0, r, g, b ); + } -public void scol0a(int icol0, int r, int g, int b, double a) { - if (set_stream() == -1) return; - plplotjavac.plscol0a(icol0, r, g, b, a); -} + public void scol0a( int icol0, int r, int g, int b, double a ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscol0a( icol0, r, g, b, a ); + } -public void scolbg(int r, int g, int b) { - if (set_stream() == -1) return; - plplotjavac.plscolbg(r, g, b); -} + public void scolbg( int r, int g, int b ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscolbg( r, g, b ); + } -public void scolbga(int r, int g, int b, double a) { - if (set_stream() == -1) return; - plplotjavac.plscolbga(r, g, b, a); -} + public void scolbga( int r, int g, int b, double a ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscolbga( r, g, b, a ); + } -public void scolor(int color) { - if (set_stream() == -1) return; - plplotjavac.plscolor(color); -} + public void scolor( int color ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscolor( color ); + } -public void scompression(int compression) { - if (set_stream() == -1) return; - plplotjavac.plscompression(compression); -} + public void scompression( int compression ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plscompression( compression ); + } -public void sdev(String devname) { - if (set_stream() == -1) return; - plplotjavac.plsdev(devname); -} + public void sdev( String devname ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsdev( devname ); + } -public void sdidev(double mar, double aspect, double jx, double jy) { - if (set_stream() == -1) return; - plplotjavac.plsdidev(mar, aspect, jx, jy); -} + public void sdidev( double mar, double aspect, double jx, double jy ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsdidev( mar, aspect, jx, jy ); + } -public void sdimap(int dimxmin, int dimxmax, int dimymin, int dimymax, - double dimxpmm, double dimypmm) { - if (set_stream() == -1) return; - plplotjavac.plsdimap(dimxmin, dimxmax, dimymin, dimymax, dimxpmm, dimypmm); -} + public void sdimap( int dimxmin, int dimxmax, int dimymin, int dimymax, + double dimxpmm, double dimypmm ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsdimap( dimxmin, dimxmax, dimymin, dimymax, dimxpmm, dimypmm ); + } -public void sdiori(double rot) { - if (set_stream() == -1) return; - plplotjavac.plsdiori(rot); -} + public void sdiori( double rot ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsdiori( rot ); + } -public void sdiplt(double xmin, double ymin, double xmax, double ymax) { - if (set_stream() == -1) return; - plplotjavac.plsdiplt(xmin, ymin, xmax, ymax); -} + public void sdiplt( double xmin, double ymin, double xmax, double ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsdiplt( xmin, ymin, xmax, ymax ); + } -public void sdiplz(double xmin, double ymin, double xmax, double ymax) { - if (set_stream() == -1) return; - plplotjavac.plsdiplz(xmin, ymin, xmax, ymax); -} + public void sdiplz( double xmin, double ymin, double xmax, double ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsdiplz( xmin, ymin, xmax, ymax ); + } -public void seed(long s) { - if (set_stream() == -1) return; - plplotjavac.plseed(s); -} + public void seed( long s ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plseed( s ); + } -public void sesc(char esc) { - if (set_stream() == -1) return; - plplotjavac.plsesc(esc); -} + public void sesc( char esc ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsesc( esc ); + } -public void setopt(String opt, String optarg) { - if (set_stream() == -1) return; - plplotjavac.plsetopt(opt, optarg); -} + public void setopt( String opt, String optarg ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsetopt( opt, optarg ); + } -public void sfam(int fam, int num, int bmax) { - if (set_stream() == -1) return; - plplotjavac.plsfam(fam, num, bmax); -} + public void sfam( int fam, int num, int bmax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsfam( fam, num, bmax ); + } -public void sfci(long fci) { - if (set_stream() == -1) return; - plplotjavac.plsfci(fci); -} + public void sfci( long fci ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsfci( fci ); + } -public void sfnam(String fnam) { - if (set_stream() == -1) return; - plplotjavac.plsfnam(fnam); -} + public void sfnam( String fnam ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsfnam( fnam ); + } -public void sfont(int family, int style, int weight) { - if (set_stream() == -1) return; - plplotjavac.plsfont(family, style, weight); -} + public void sfont( int family, int style, int weight ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsfont( family, style, weight ); + } -public void shades( double[][] a, double xmin, double xmax, double ymin, - double ymax, double[] clevel, int fill_width, int cont_color, - int cont_width, boolean rectangular, - double[][] pltr, double[][] OBJECT_DATA) { - if (set_stream() == -1) return; - plplotjavac.plshades( a, xmin, xmax, ymin, ymax, clevel, fill_width, - cont_color, cont_width, rectangular, pltr, OBJECT_DATA); -} + public void shades( double[][] a, double xmin, double xmax, double ymin, + double ymax, double[] clevel, int fill_width, int cont_color, + int cont_width, boolean rectangular, + double[][] pltr, double[][] OBJECT_DATA ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plshades( a, xmin, xmax, ymin, ymax, clevel, fill_width, + cont_color, cont_width, rectangular, pltr, OBJECT_DATA ); + } -public void shade(double[][] a, double left, double right, double bottom, - double top, double shade_min, double shade_max, int sh_cmap, - double sh_color, int sh_width, int min_color, int min_width, - int max_color, int max_width, boolean rectangular, - double[][] pltr, double[][] OBJECT_DATA) { - if (set_stream() == -1) return; - plplotjavac.plshade(a, left, right, bottom, top, shade_min, shade_max, - sh_cmap, sh_color, sh_width, min_color, min_width, - max_color, max_width, rectangular, pltr, OBJECT_DATA); -} + public void shade( double[][] a, double left, double right, double bottom, + double top, double shade_min, double shade_max, int sh_cmap, + double sh_color, int sh_width, int min_color, int min_width, + int max_color, int max_width, boolean rectangular, + double[][] pltr, double[][] OBJECT_DATA ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plshade( a, left, right, bottom, top, shade_min, shade_max, + sh_cmap, sh_color, sh_width, min_color, min_width, + max_color, max_width, rectangular, pltr, OBJECT_DATA ); + } -public void slabelfunc(PLCallbackLabel label, Object obj) { - if (set_stream() == -1) return; - plplotjavac.plslabelfunc(label,obj); -} + public void slabelfunc( PLCallbackLabel label, Object obj ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plslabelfunc( label, obj ); + } -public void slabelfunc(PLCallbackLabel label) { - if (set_stream() == -1) return; - plplotjavac.plslabelfunc(label,null); -} + public void slabelfunc( PLCallbackLabel label ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plslabelfunc( label, null ); + } -public void smaj(double def, double scale) { - if (set_stream() == -1) return; - plplotjavac.plsmaj(def, scale); -} + public void smaj( double def, double scale ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsmaj( def, scale ); + } -public void smin(double def, double scale) { - if (set_stream() == -1) return; - plplotjavac.plsmin(def, scale); -} + public void smin( double def, double scale ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsmin( def, scale ); + } -public void sori(int ori) { - if (set_stream() == -1) return; - plplotjavac.plsori(ori); -} + public void sori( int ori ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsori( ori ); + } -public void spage(double xp, double yp, int xleng, int yleng, int xoff, int yoff) { - if (set_stream() == -1) return; - plplotjavac.plspage(xp, yp, xleng, yleng, xoff, yoff); -} + public void spage( double xp, double yp, int xleng, int yleng, int xoff, int yoff ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plspage( xp, yp, xleng, yleng, xoff, yoff ); + } -public void spal0(String filename) { - if (set_stream() == -1) return; - plplotjavac.plspal0(filename); -} + public void spal0( String filename ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plspal0( filename ); + } -public void spal1(String filename, boolean interpolate) { - if (set_stream() == -1) return; - plplotjavac.plspal1(filename,interpolate); -} + public void spal1( String filename, boolean interpolate ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plspal1( filename, interpolate ); + } -public void spause(boolean pause) { - if (set_stream() == -1) return; - plplotjavac.plspause(pause); -} + public void spause( boolean pause ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plspause( pause ); + } -public void sstrm(int strm) { - if (set_stream() == -1) return; - plplotjavac.plsstrm(strm); -} + public void sstrm( int strm ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsstrm( strm ); + } -public void ssub(int nx, int ny) { - if (set_stream() == -1) return; - plplotjavac.plssub(nx, ny); -} + public void ssub( int nx, int ny ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plssub( nx, ny ); + } -public void ssym(double def, double scale) { - if (set_stream() == -1) return; - plplotjavac.plssym(def, scale); -} + public void ssym( double def, double scale ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plssym( def, scale ); + } -public void star(int nx, int ny) { - if (set_stream() == -1) return; - plplotjavac.plstar(nx, ny); -} + public void star( int nx, int ny ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plstar( nx, ny ); + } -public void start(String devname, int nx, int ny) { - if (set_stream() == -1) return; - plplotjavac.plstart(devname, nx, ny); -} + public void start( String devname, int nx, int ny ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plstart( devname, nx, ny ); + } -public void stripa(int id, int pen, double x, double y) { - if (set_stream() == -1) return; - plplotjavac.plstripa(id, pen, x, y); -} + public void stripa( int id, int pen, double x, double y ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plstripa( id, pen, x, y ); + } -public void stripc(int[] id, String xspec, String yspec, - double xmin, double xmax, double xjump, - double ymin, double ymax, double xlpos, double ylpos, - boolean y_ascl, boolean acc, int colbox, int collab, - int[] colline, int[] styline, String[] legline, - String labx, String laby, String labtop) { - if (set_stream() == -1) return; - plplotjavac.plstripc(id, xspec, yspec, xmin, xmax, xjump, ymin, ymax, - xlpos, ylpos, y_ascl, acc, colbox, collab, colline, - styline, legline, labx, laby, labtop); -} + public void stripc( int[] id, String xspec, String yspec, + double xmin, double xmax, double xjump, + double ymin, double ymax, double xlpos, double ylpos, + boolean y_ascl, boolean acc, int colbox, int collab, + int[] colline, int[] styline, String[] legline, + String labx, String laby, String labtop ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plstripc( id, xspec, yspec, xmin, xmax, xjump, ymin, ymax, + xlpos, ylpos, y_ascl, acc, colbox, collab, colline, + styline, legline, labx, laby, labtop ); + } -public void stripd(int id) { - if (set_stream() == -1) return; - plplotjavac.plstripd(id); -} + public void stripd( int id ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plstripd( id ); + } -public void styl(int[] mark, int[] space) { - if (set_stream() == -1) return; - plplotjavac.plstyl(mark, space); -} + public void styl( int[] mark, int[] space ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plstyl( mark, space ); + } -public void svect(double[] arrow_x, double[] arrow_y, boolean fill) { - if (set_stream() == -1) return; - plplotjavac.plsvect(arrow_x, arrow_y, fill); -} + public void svect( double[] arrow_x, double[] arrow_y, boolean fill ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsvect( arrow_x, arrow_y, fill ); + } -public void svpa(double xmin, double xmax, double ymin, double ymax) { - if (set_stream() == -1) return; - plplotjavac.plsvpa(xmin, xmax, ymin, ymax); -} + public void svpa( double xmin, double xmax, double ymin, double ymax ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsvpa( xmin, xmax, ymin, ymax ); + } -public void sxax(int digmax, int digits) { - if (set_stream() == -1) return; - plplotjavac.plsxax(digmax, digits); -} + public void sxax( int digmax, int digits ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsxax( digmax, digits ); + } -public void syax(int digmax, int digits) { - if (set_stream() == -1) return; - plplotjavac.plsyax(digmax, digits); -} + public void syax( int digmax, int digits ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsyax( digmax, digits ); + } -public void sym(double[] x, double[] y, int code) { - if (set_stream() == -1) return; - plplotjavac.plsym(x, y, code); -} + public void sym( double[] x, double[] y, int code ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plsym( x, y, code ); + } -public void szax(int digmax, int digits) { - if (set_stream() == -1) return; - plplotjavac.plszax(digmax, digits); -} + public void szax( int digmax, int digits ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plszax( digmax, digits ); + } -public void text() { - if (set_stream() == -1) return; - plplotjavac.pltext(); -} + public void text() + { + if ( set_stream() == -1 ) return; + plplotjavac.pltext(); + } -public void timefmt(String fmt) { - if (set_stream() == -1) return; - plplotjavac.pltimefmt(fmt); -} + public void timefmt( String fmt ) + { + if ( set_stream() == -1 ) return; + plplotjavac.pltimefmt( fmt ); + } -public void vasp(double aspect) { - if (set_stream() == -1) return; - plplotjavac.plvasp(aspect); -} + public void vasp( double aspect ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plvasp( aspect ); + } -public void vect(double[][] u, double[][] v, double scale, double[][] pltr, double[][] OBJECT_DATA) { - if (set_stream() == -1) return; - plplotjavac.plvect(u, v, scale, pltr, OBJECT_DATA); -} + public void vect( double[][] u, double[][] v, double scale, double[][] pltr, double[][] OBJECT_DATA ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plvect( u, v, scale, pltr, OBJECT_DATA ); + } -public void vpas(double xmin, double xmax, double ymin, double ymax, double aspect) { - if (set_stream() == -1) return; - plplotjavac.plvpas(xmin, xmax, ymin, ymax, aspect); -} + public void vpas( double xmin, double xmax, double ymin, double ymax, double aspect ) + { + if ( set_stream() == -1 ) return; + plplotjavac.plvpas( xmin, xmax, ymin, ymax, aspect ); + } -public void vpor(double xmin, double xmax, double ymin, double ym... [truncated message content] |
From: <ai...@us...> - 2009-12-08 00:05:14
|
Revision: 10707 http://plplot.svn.sourceforge.net/plplot/?rev=10707&view=rev Author: airwin Date: 2009-12-08 00:05:05 +0000 (Tue, 08 Dec 2009) Log Message: ----------- Style D language results with uncrustify. Modified Paths: -------------- trunk/bindings/d/plplot.d trunk/examples/d/x01d.d trunk/examples/d/x02d.d trunk/examples/d/x03d.d trunk/examples/d/x04d.d trunk/examples/d/x05d.d trunk/examples/d/x06d.d trunk/examples/d/x07d.d trunk/examples/d/x08d.d trunk/examples/d/x09d.d trunk/examples/d/x10d.d trunk/examples/d/x11d.d trunk/examples/d/x12d.d trunk/examples/d/x13d.d trunk/examples/d/x14d.d trunk/examples/d/x15d.d trunk/examples/d/x16d.d trunk/examples/d/x17d.d trunk/examples/d/x18d.d trunk/examples/d/x19d.d trunk/examples/d/x20d.d trunk/examples/d/x21d.d trunk/examples/d/x22d.d trunk/examples/d/x23d.d trunk/examples/d/x24d.d trunk/examples/d/x25d.d trunk/examples/d/x26d.d trunk/examples/d/x27d.d trunk/examples/d/x28d.d trunk/examples/d/x29d.d trunk/examples/d/x30d.d trunk/examples/d/x31d.d trunk/scripts/style_source.sh Modified: trunk/bindings/d/plplot.d =================================================================== --- trunk/bindings/d/plplot.d 2009-12-08 00:00:36 UTC (rev 10706) +++ trunk/bindings/d/plplot.d 2009-12-08 00:05:05 UTC (rev 10707) @@ -7,11 +7,11 @@ // certain functions must be declared as C functions so that PLplot // can handle them -extern (C) { - alias PLINT function(PLFLT, PLFLT) def_func; - alias void function(PLINT, PLFLT* , PLFLT*) fill_func; - alias void function(PLFLT, PLFLT, PLFLT*, PLFLT*, PLPointer) pltr_func; - alias void function(PLINT, PLFLT*, PLFLT*) mapform_func; +extern ( C ) { +alias PLINT function( PLFLT, PLFLT ) def_func; +alias void function( PLINT, PLFLT*, PLFLT* ) fill_func; +alias void function( PLFLT, PLFLT, PLFLT*, PLFLT*, PLPointer ) pltr_func; +alias void function( PLINT, PLFLT*, PLFLT* ) mapform_func; } // D definition of PLcGrid and PLcGrid2 @@ -29,180 +29,185 @@ } // helper function to convert D dynamic arrays in C dynamic arrays -private PLFLT** convert_array(PLFLT[][] a) +private PLFLT** convert_array( PLFLT[][] a ) { - if(!a) - return null; - - size_t nx=a.length; - size_t ny=a[0].length; + if ( !a ) + return null; - PLFLT** c_a = (new PLFLT*[nx]).ptr; - for(size_t i=0; i<nx; i++) { - assert(ny==a[i].length, "convert_array(): Array must be 2 dimensional!"); - c_a[i] = a[i].ptr; - } - - return c_a; + size_t nx = a.length; + size_t ny = a[0].length; + + PLFLT ** c_a = ( new PLFLT *[nx] ).ptr; + for ( size_t i = 0; i < nx; i++ ) + { + assert( ny == a[i].length, "convert_array(): Array must be 2 dimensional!" ); + c_a[i] = a[i].ptr; + } + + return c_a; } /* Process options list using current options info. */ -int plparseopts(char[][] args, PLINT mode) +int plparseopts( char[][] args, PLINT mode ) { - char*[] c_args = new char*[args.length]; - foreach( size_t i, char[] arg; args ) - c_args[i] = toStringz(arg); - int argc = c_args.length; - return c_plparseopts( &argc, cast(char**)c_args, mode ); + char*[] c_args = new char*[args.length]; + foreach ( size_t i, char[] arg; args ) + c_args[i] = toStringz( arg ); + int argc = c_args.length; + return c_plparseopts( &argc, cast(char**) c_args, mode ); } /* simple arrow plotter. */ -void plvect(PLFLT[][] u, PLFLT[][] v, PLFLT scale, pltr_func pltr=null, PLPointer pltr_data=null) +void plvect( PLFLT[][] u, PLFLT[][] v, PLFLT scale, pltr_func pltr = null, PLPointer pltr_data = null ) { - PLINT nx=u.length; - PLINT ny=u[0].length; - assert(nx==v.length, "plvect(): Arrays must be of same length!"); - assert(ny==v[0].length, "plvect(): Arrays must be of same length!"); - - c_plvect(convert_array(u), convert_array(v), nx, ny, scale, pltr, pltr_data); + PLINT nx = u.length; + PLINT ny = u[0].length; + assert( nx == v.length, "plvect(): Arrays must be of same length!" ); + assert( ny == v[0].length, "plvect(): Arrays must be of same length!" ); + + c_plvect( convert_array( u ), convert_array( v ), nx, ny, scale, pltr, pltr_data ); } -void plvect(PLFLT[][] u, PLFLT[][] v, PLFLT scale, ref PLcGrid cgrid) +void plvect( PLFLT[][] u, PLFLT[][] v, PLFLT scale, ref PLcGrid cgrid ) { - PLINT nx=u.length; - PLINT ny=u[0].length; - assert(nx==v.length, "plvect(): Arrays must be of same length!"); - assert(ny==v[0].length, "plvect(): Arrays must be of same length!"); + PLINT nx = u.length; + PLINT ny = u[0].length; + assert( nx == v.length, "plvect(): Arrays must be of same length!" ); + assert( ny == v[0].length, "plvect(): Arrays must be of same length!" ); - c_PLcGrid c; - c.xg = cgrid.xg.ptr; - c.nx = cgrid.xg.length; - c.yg = cgrid.yg.ptr; - c.ny = cgrid.yg.length; - c.zg = cgrid.zg.ptr; - c.nz = cgrid.zg.length; + c_PLcGrid c; + c.xg = cgrid.xg.ptr; + c.nx = cgrid.xg.length; + c.yg = cgrid.yg.ptr; + c.ny = cgrid.yg.length; + c.zg = cgrid.zg.ptr; + c.nz = cgrid.zg.length; - c_plvect(convert_array(u), convert_array(v), nx, ny, scale, &pltr1, &c); + c_plvect( convert_array( u ), convert_array( v ), nx, ny, scale, &pltr1, &c ); } -void plvect(PLFLT[][] u, PLFLT[][] v, PLFLT scale, ref PLcGrid2 cgrid2) +void plvect( PLFLT[][] u, PLFLT[][] v, PLFLT scale, ref PLcGrid2 cgrid2 ) { - PLINT nx=u.length; - PLINT ny=u[0].length; - assert(nx==v.length, "plvect(): Arrays must be of same length!"); - assert(ny==v[0].length, "plvect(): Arrays must be of same length!"); + PLINT nx = u.length; + PLINT ny = u[0].length; + assert( nx == v.length, "plvect(): Arrays must be of same length!" ); + assert( ny == v[0].length, "plvect(): Arrays must be of same length!" ); - c_PLcGrid2 c2; - c2.xg = convert_array(cgrid2.xg); - c2.yg = convert_array(cgrid2.yg); - c2.zg = convert_array(cgrid2.zg); - c2.nx = cgrid2.xg.length; - c2.ny = cgrid2.xg[0].length; - if(cgrid2.yg) { - assert(c2.nx==cgrid2.yg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.yg[0].length, "plcont(): Arrays must be of same length!"); - } - if(cgrid2.zg) { - assert(c2.nx==cgrid2.zg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.zg[0].length, "plcont(): Arrays must be of same length!"); - } + c_PLcGrid2 c2; + c2.xg = convert_array( cgrid2.xg ); + c2.yg = convert_array( cgrid2.yg ); + c2.zg = convert_array( cgrid2.zg ); + c2.nx = cgrid2.xg.length; + c2.ny = cgrid2.xg[0].length; + if ( cgrid2.yg ) + { + assert( c2.nx == cgrid2.yg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.yg[0].length, "plcont(): Arrays must be of same length!" ); + } + if ( cgrid2.zg ) + { + assert( c2.nx == cgrid2.zg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.zg[0].length, "plcont(): Arrays must be of same length!" ); + } - c_plvect(convert_array(u), convert_array(v), nx, ny, scale, &pltr2, &c2); + c_plvect( convert_array( u ), convert_array( v ), nx, ny, scale, &pltr2, &c2 ); } -void plsvect(PLFLT[] arrowx, PLFLT[] arrowy, PLBOOL fill) +void plsvect( PLFLT[] arrowx, PLFLT[] arrowy, PLBOOL fill ) { - PLINT npts=arrowx.length; - assert(npts==arrowy.length, "plsvect(): Arrays must be of same length!"); - c_plsvect(arrowx.ptr, arrowy.ptr, npts, fill); + PLINT npts = arrowx.length; + assert( npts == arrowy.length, "plsvect(): Arrays must be of same length!" ); + c_plsvect( arrowx.ptr, arrowy.ptr, npts, fill ); } /* This functions similarly to plbox() except that the origin of the axes */ /* is placed at the user-specified point (x0, y0). */ -void plaxes(PLFLT x0, PLFLT y0, string xopt, PLFLT xtick, PLINT nxsub, - string yopt, PLFLT ytick, PLINT nysub) +void plaxes( PLFLT x0, PLFLT y0, string xopt, PLFLT xtick, PLINT nxsub, + string yopt, PLFLT ytick, PLINT nysub ) { - c_plaxes(x0, y0, toStringz(xopt), xtick, nxsub, toStringz(yopt), ytick, nysub); + c_plaxes( x0, y0, toStringz( xopt ), xtick, nxsub, toStringz( yopt ), ytick, nysub ); } /* Plot a histogram using x to store data values and y to store frequencies */ -void plbin(PLFLT[] x, PLFLT[] y, PLINT opt) +void plbin( PLFLT[] x, PLFLT[] y, PLINT opt ) { - PLINT nbin=x.length; - assert(nbin==y.length, "plbin(): Arrays must be of same length!"); - c_plbin(nbin, x.ptr, y.ptr, opt); + PLINT nbin = x.length; + assert( nbin == y.length, "plbin(): Arrays must be of same length!" ); + c_plbin( nbin, x.ptr, y.ptr, opt ); } /* This draws a box around the current viewport. */ -void plbox(string xopt, PLFLT xtick, PLINT nxsub, string yopt, PLFLT ytick, PLINT nysub) +void plbox( string xopt, PLFLT xtick, PLINT nxsub, string yopt, PLFLT ytick, PLINT nysub ) { - c_plbox(toStringz(xopt), xtick, nxsub, toStringz(yopt), ytick, nysub); + c_plbox( toStringz( xopt ), xtick, nxsub, toStringz( yopt ), ytick, nysub ); } /* This is the 3-d analogue of plbox(). */ -void plbox3(string xopt, string xlabel, PLFLT xtick, PLINT nsubx, - string yopt, string ylabel, PLFLT ytick, PLINT nsuby, - string zopt, string zlabel, PLFLT ztick, PLINT nsubz) +void plbox3( string xopt, string xlabel, PLFLT xtick, PLINT nsubx, + string yopt, string ylabel, PLFLT ytick, PLINT nsuby, + string zopt, string zlabel, PLFLT ztick, PLINT nsubz ) { - c_plbox3(toStringz(xopt), toStringz(xlabel), xtick, nsubx, - toStringz(yopt), toStringz(ylabel), ytick, nsuby, - toStringz(zopt), toStringz(zlabel), ztick, nsubz); + c_plbox3( toStringz( xopt ), toStringz( xlabel ), xtick, nsubx, + toStringz( yopt ), toStringz( ylabel ), ytick, nsuby, + toStringz( zopt ), toStringz( zlabel ), ztick, nsubz ); } /* Draws a contour plot from data in f(nx,ny). Is just a front-end to * plfcont, with a particular choice for f2eval and f2eval_data. */ -void plcont(PLFLT[][] f, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT[] clevel, - pltr_func pltr, PLPointer pltr_data=null) +void plcont( PLFLT[][] f, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT[] clevel, + pltr_func pltr, PLPointer pltr_data = null ) { - PLINT nx=f.length; - PLINT ny=f[0].length; + PLINT nx = f.length; + PLINT ny = f[0].length; - c_plcont(convert_array(f), nx, ny, kx, lx, ky, ly, clevel.ptr, clevel.length, - pltr, pltr_data); + c_plcont( convert_array( f ), nx, ny, kx, lx, ky, ly, clevel.ptr, clevel.length, + pltr, pltr_data ); } -void plcont(PLFLT[][] f, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT[] clevel, - ref PLcGrid cgrid) +void plcont( PLFLT[][] f, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT[] clevel, + ref PLcGrid cgrid ) { - PLINT nx=f.length; - PLINT ny=f[0].length; + PLINT nx = f.length; + PLINT ny = f[0].length; - c_PLcGrid c; - c.xg = cgrid.xg.ptr; - c.nx = cgrid.xg.length; - c.yg = cgrid.yg.ptr; - c.ny = cgrid.yg.length; - c.zg = cgrid.zg.ptr; - c.nz = cgrid.zg.length; - - c_plcont(convert_array(f), nx, ny, kx, lx, ky, ly, clevel.ptr, clevel.length, - &pltr1, &c); + c_PLcGrid c; + c.xg = cgrid.xg.ptr; + c.nx = cgrid.xg.length; + c.yg = cgrid.yg.ptr; + c.ny = cgrid.yg.length; + c.zg = cgrid.zg.ptr; + c.nz = cgrid.zg.length; + + c_plcont( convert_array( f ), nx, ny, kx, lx, ky, ly, clevel.ptr, clevel.length, + &pltr1, &c ); } -void plcont(PLFLT[][] f, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT[] clevel, - ref PLcGrid2 cgrid2) +void plcont( PLFLT[][] f, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT[] clevel, + ref PLcGrid2 cgrid2 ) { - PLINT nx=f.length; - PLINT ny=f[0].length; + PLINT nx = f.length; + PLINT ny = f[0].length; - c_PLcGrid2 c2; - c2.xg = convert_array(cgrid2.xg); - c2.yg = convert_array(cgrid2.yg); - c2.zg = convert_array(cgrid2.zg); - c2.nx = cgrid2.xg.length; - c2.ny = cgrid2.xg[0].length; - if(cgrid2.yg) { - assert(c2.nx==cgrid2.yg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.yg[0].length, "plcont(): Arrays must be of same length!"); - } - if(cgrid2.zg) { - assert(c2.nx==cgrid2.zg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.zg[0].length, "plcont(): Arrays must be of same length!"); - } + c_PLcGrid2 c2; + c2.xg = convert_array( cgrid2.xg ); + c2.yg = convert_array( cgrid2.yg ); + c2.zg = convert_array( cgrid2.zg ); + c2.nx = cgrid2.xg.length; + c2.ny = cgrid2.xg[0].length; + if ( cgrid2.yg ) + { + assert( c2.nx == cgrid2.yg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.yg[0].length, "plcont(): Arrays must be of same length!" ); + } + if ( cgrid2.zg ) + { + assert( c2.nx == cgrid2.zg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.zg[0].length, "plcont(): Arrays must be of same length!" ); + } - c_plcont(convert_array(f), nx, ny, kx, lx, ky, ly, clevel.ptr, clevel.length, - &pltr2, &c2); + c_plcont( convert_array( f ), nx, ny, kx, lx, ky, ly, clevel.ptr, clevel.length, + &pltr2, &c2 ); } /* Draws a contour plot using the function evaluator f2eval and data stored @@ -212,562 +217,571 @@ //void plfcont(PLFLT function(PLINT , PLINT , PLPointer )f2eval, PLPointer f2eval_data, PLINT nx, PLINT ny, PLINT kx, PLINT lx, PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, void function(PLFLT , PLFLT , PLFLT *, PLFLT *, PLPointer )pltr, PLPointer pltr_data); /* Plot horizontal error bars (xmin(i),y(i)) to (xmax(i),y(i)) */ -void plerrx(PLFLT[] xmin, PLFLT[] xmax, PLFLT[] y) +void plerrx( PLFLT[] xmin, PLFLT[] xmax, PLFLT[] y ) { - PLINT n=y.length; - assert(n==xmin.length, "plerrx(): Arrays must be of same length!"); - assert(n==xmax.length, "plerrx(): Arrays must be of same length!"); - c_plerrx(n, xmin.ptr, xmax.ptr, y.ptr); + PLINT n = y.length; + assert( n == xmin.length, "plerrx(): Arrays must be of same length!" ); + assert( n == xmax.length, "plerrx(): Arrays must be of same length!" ); + c_plerrx( n, xmin.ptr, xmax.ptr, y.ptr ); } /* Plot vertical error bars (x,ymin(i)) to (x(i),ymax(i)) */ -void plerry(PLFLT[] x, PLFLT[] ymin, PLFLT[] ymax) +void plerry( PLFLT[] x, PLFLT[] ymin, PLFLT[] ymax ) { - PLINT n=x.length; - assert(n==ymin.length, "plerry(): Arrays must be of same length!"); - assert(n==ymax.length, "plerry(): Arrays must be of same length!"); - c_plerry(n, x.ptr, ymin.ptr, ymax.ptr); + PLINT n = x.length; + assert( n == ymin.length, "plerry(): Arrays must be of same length!" ); + assert( n == ymax.length, "plerry(): Arrays must be of same length!" ); + c_plerry( n, x.ptr, ymin.ptr, ymax.ptr ); } /* Pattern fills the polygon bounded by the input points. */ -void plfill(PLFLT[] x, PLFLT[] y) +void plfill( PLFLT[] x, PLFLT[] y ) { - PLINT n=x.length; - assert(n==y.length, "plfill(): Arrays must be of same length!"); - c_plfill(n, x.ptr, y.ptr); + PLINT n = x.length; + assert( n == y.length, "plfill(): Arrays must be of same length!" ); + c_plfill( n, x.ptr, y.ptr ); } /* Pattern fills the 3d polygon bounded by the input points. */ -void plfill3(PLFLT[] x, PLFLT[] y, PLFLT[] z) +void plfill3( PLFLT[] x, PLFLT[] y, PLFLT[] z ) { - PLINT n=x.length; - assert(n==y.length, "plfill3(): Arrays must be of same length!"); - assert(n==z.length, "plfill3(): Arrays must be of same length!"); - c_plfill3(n, x.ptr, y.ptr, z.ptr); + PLINT n = x.length; + assert( n == y.length, "plfill3(): Arrays must be of same length!" ); + assert( n == z.length, "plfill3(): Arrays must be of same length!" ); + c_plfill3( n, x.ptr, y.ptr, z.ptr ); } /* Get the current device (keyword) name */ -void plgdev(out string p_dev) +void plgdev( out string p_dev ) { - p_dev.length = 1024; - c_plgdev(p_dev.ptr); - p_dev=toString(p_dev.ptr); + p_dev.length = 1024; + c_plgdev( p_dev.ptr ); + p_dev = toString( p_dev.ptr ); } /* Get the (current) output file name. Must be preallocated to >80 bytes */ -void plgfnam(out string fnam) +void plgfnam( out string fnam ) { - fnam.length = 1024; - c_plgfnam(fnam.ptr); - fnam=toString(fnam.ptr); + fnam.length = 1024; + c_plgfnam( fnam.ptr ); + fnam = toString( fnam.ptr ); } /* Draw gradient in polygon. */ -void plgradient(PLFLT[] x, PLFLT[] y, PLFLT angle) +void plgradient( PLFLT[] x, PLFLT[] y, PLFLT angle ) { - PLINT n=x.length; - assert(n==y.length, "plgradient(): Arrays must be of same length!"); - c_plgradient(n, x.ptr, y.ptr, angle); + PLINT n = x.length; + assert( n == y.length, "plgradient(): Arrays must be of same length!" ); + c_plgradient( n, x.ptr, y.ptr, angle ); } /* grid irregularly sampled data */ -void plgriddata(PLFLT[] x, PLFLT[] y, PLFLT[] z, PLFLT[] xg, PLFLT[] yg, PLFLT[][] zg, PLINT type, PLFLT data) +void plgriddata( PLFLT[] x, PLFLT[] y, PLFLT[] z, PLFLT[] xg, PLFLT[] yg, PLFLT[][] zg, PLINT type, PLFLT data ) { - PLINT npts = x.length; - assert(npts==y.length, "plgriddata(): Arrays must be of same length!"); - assert(npts==z.length, "plgriddata(): Arrays must be of same length!"); - - PLINT nxg = xg.length; - PLINT nyg = yg.length; - assert(nxg==zg.length, "plgriddata(): Arrays must be of same length!"); - assert(nyg==zg[0].length, "plgriddata(): Arrays must be of same length!"); - - c_plgriddata(x.ptr, y.ptr, z.ptr, npts, xg.ptr, nxg, yg.ptr, nyg, convert_array(zg), type, data); + PLINT npts = x.length; + assert( npts == y.length, "plgriddata(): Arrays must be of same length!" ); + assert( npts == z.length, "plgriddata(): Arrays must be of same length!" ); + + PLINT nxg = xg.length; + PLINT nyg = yg.length; + assert( nxg == zg.length, "plgriddata(): Arrays must be of same length!" ); + assert( nyg == zg[0].length, "plgriddata(): Arrays must be of same length!" ); + + c_plgriddata( x.ptr, y.ptr, z.ptr, npts, xg.ptr, nxg, yg.ptr, nyg, convert_array( zg ), type, data ); } /* Get the current library version number */ -void plgver(out string p_ver) +void plgver( out string p_ver ) { - p_ver.length = 1024; - c_plgver(p_ver.ptr); - p_ver=toString(p_ver.ptr); + p_ver.length = 1024; + c_plgver( p_ver.ptr ); + p_ver = toString( p_ver.ptr ); } /* Draws a histogram of n values of a variable in array data[0..n-1] */ -void plhist(PLFLT[] data, PLFLT datmin, PLFLT datmax, PLINT nbin, PLINT opt) +void plhist( PLFLT[] data, PLFLT datmin, PLFLT datmax, PLINT nbin, PLINT opt ) { - c_plhist(data.length, data.ptr, datmin, datmax, nbin, opt); + c_plhist( data.length, data.ptr, datmin, datmax, nbin, opt ); } /* Simple routine for labelling graphs. */ -void pllab(string xlabel, string ylabel, string tlabel) +void pllab( string xlabel, string ylabel, string tlabel ) { - c_pllab(toStringz(xlabel), toStringz(ylabel), toStringz(tlabel)); + c_pllab( toStringz( xlabel ), toStringz( ylabel ), toStringz( tlabel )); } /* Draws line segments connecting a series of points. */ -void plline(PLFLT[] x, PLFLT[] y) +void plline( PLFLT[] x, PLFLT[] y ) { - PLINT n=x.length; - assert(n==y.length, "plline(): Arrays must be of same length!"); - c_plline(n, x.ptr, y.ptr); + PLINT n = x.length; + assert( n == y.length, "plline(): Arrays must be of same length!" ); + c_plline( n, x.ptr, y.ptr ); } /* Draws a line in 3 space. */ -void plline3(PLFLT[] x, PLFLT[] y, PLFLT[] z) +void plline3( PLFLT[] x, PLFLT[] y, PLFLT[] z ) { - PLINT n=x.length; - assert(n==y.length, "plline3(): Arrays must be of same length!"); - assert(n==z.length, "plline3(): Arrays must be of same length!"); - c_plline3(n, x.ptr, y.ptr, z.ptr); + PLINT n = x.length; + assert( n == y.length, "plline3(): Arrays must be of same length!" ); + assert( n == z.length, "plline3(): Arrays must be of same length!" ); + c_plline3( n, x.ptr, y.ptr, z.ptr ); } /* plot continental outline in world coordinates */ -void plmap(mapform_func mapform, string type, PLFLT minlong, PLFLT maxlong, - PLFLT minlat, PLFLT maxlat) +void plmap( mapform_func mapform, string type, PLFLT minlong, PLFLT maxlong, + PLFLT minlat, PLFLT maxlat ) { - c_plmap(mapform, toStringz(type), minlong, maxlong, minlat, maxlat); + c_plmap( mapform, toStringz( type ), minlong, maxlong, minlat, maxlat ); } /* Plots a mesh representation of the function z[x][y]. */ -void plmesh(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt) +void plmesh( PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt ) { - PLINT nx=z.length; - PLINT ny=z[0].length; - - assert(nx==x.length, "plmesh(): Arrays must be of same length!"); - assert(ny==y.length, "plmesh(): Arrays must be of same length!"); + PLINT nx = z.length; + PLINT ny = z[0].length; - c_plmesh(x.ptr, y.ptr, convert_array(z), nx, ny, opt); + assert( nx == x.length, "plmesh(): Arrays must be of same length!" ); + assert( ny == y.length, "plmesh(): Arrays must be of same length!" ); + + c_plmesh( x.ptr, y.ptr, convert_array( z ), nx, ny, opt ); } /* Plots a mesh representation of the function z[x][y] with contour */ -void plmeshc(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel) +void plmeshc( PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel ) { - PLINT nx=z.length; - PLINT ny=z[0].length; - - assert(nx==x.length, "plmeshc(): Arrays must be of same length!"); - assert(ny==y.length, "plmeshc(): Arrays must be of same length!"); + PLINT nx = z.length; + PLINT ny = z[0].length; - c_plmeshc(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length); + assert( nx == x.length, "plmeshc(): Arrays must be of same length!" ); + assert( ny == y.length, "plmeshc(): Arrays must be of same length!" ); + + c_plmeshc( x.ptr, y.ptr, convert_array( z ), nx, ny, opt, clevel.ptr, clevel.length ); } /* Prints out "text" at specified position relative to viewport */ -void plmtex(string side, PLFLT disp, PLFLT pos, PLFLT just, string text) +void plmtex( string side, PLFLT disp, PLFLT pos, PLFLT just, string text ) { - c_plmtex(toStringz(side), disp, pos, just, toStringz(text)); + c_plmtex( toStringz( side ), disp, pos, just, toStringz( text )); } /* Prints out "text" at specified position relative to viewport (3D)*/ -void plmtex3(string side, PLFLT disp, PLFLT pos, PLFLT just, string text) +void plmtex3( string side, PLFLT disp, PLFLT pos, PLFLT just, string text ) { - c_plmtex3(toStringz(side), disp, pos, just, toStringz(text)); + c_plmtex3( toStringz( side ), disp, pos, just, toStringz( text )); } - + /* Plots a 3-d representation of the function z[x][y]. */ -void plot3d(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLBOOL side) +void plot3d( PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLBOOL side ) { - PLINT nx=z.length; - PLINT ny=z[0].length; - - assert(nx==x.length, "plot3d(): Arrays must be of same length!"); - assert(ny==y.length, "plot3d(): Arrays must be of same length!"); + PLINT nx = z.length; + PLINT ny = z[0].length; - c_plot3d(x.ptr, y.ptr, convert_array(z), nx, ny, opt, side); + assert( nx == x.length, "plot3d(): Arrays must be of same length!" ); + assert( ny == y.length, "plot3d(): Arrays must be of same length!" ); + + c_plot3d( x.ptr, y.ptr, convert_array( z ), nx, ny, opt, side ); } /* Plots a 3-d representation of the function z[x][y] with contour. */ -void plot3dc(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel) +void plot3dc( PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel ) { - PLINT nx=z.length; - PLINT ny=z[0].length; - - assert(nx==x.length, "plot3dc(): Arrays must be of same length!"); - assert(ny==y.length, "plot3dc(): Arrays must be of same length!"); + PLINT nx = z.length; + PLINT ny = z[0].length; - c_plot3dc(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length); + assert( nx == x.length, "plot3dc(): Arrays must be of same length!" ); + assert( ny == y.length, "plot3dc(): Arrays must be of same length!" ); + + c_plot3dc( x.ptr, y.ptr, convert_array( z ), nx, ny, opt, clevel.ptr, clevel.length ); } /* Plots a 3-d representation of the function z[x][y] with contour and * y index limits. */ -void plot3dcl(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel, - PLINT ixstart, PLINT ixn, PLINT[] indexymin, PLINT[] indexymax) +void plot3dcl( PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel, + PLINT ixstart, PLINT ixn, PLINT[] indexymin, PLINT[] indexymax ) { - PLINT nx=z.length; - PLINT ny=z[0].length; - - assert(nx==x.length, "plot3dcl(): Arrays must be of same length!"); - assert(ny==y.length, "plot3dcl(): Arrays must be of same length!"); + PLINT nx = z.length; + PLINT ny = z[0].length; - c_plot3dcl(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length, - ixstart, ixn, indexymin.ptr, indexymax.ptr); + assert( nx == x.length, "plot3dcl(): Arrays must be of same length!" ); + assert( ny == y.length, "plot3dcl(): Arrays must be of same length!" ); + + c_plot3dcl( x.ptr, y.ptr, convert_array( z ), nx, ny, opt, clevel.ptr, clevel.length, + ixstart, ixn, indexymin.ptr, indexymax.ptr ); } /* Set fill pattern directly. */ -void plpat(PLINT[] inc, PLINT[] del) +void plpat( PLINT[] inc, PLINT[] del ) { - PLINT nlin=inc.length; - assert(nlin==del.length, "plpat(): Arrays must be of same length!"); - c_plpat(nlin, inc.ptr, del.ptr); + PLINT nlin = inc.length; + assert( nlin == del.length, "plpat(): Arrays must be of same length!" ); + c_plpat( nlin, inc.ptr, del.ptr ); } /* Plots array y against x for n points using ASCII code "code".*/ -void plpoin(PLFLT[] x, PLFLT[] y, PLINT code) +void plpoin( PLFLT[] x, PLFLT[] y, PLINT code ) { - PLINT n=x.length; - assert(n==y.length, "plpoin(): Arrays must be of same length!"); - c_plpoin(n, x.ptr, y.ptr, code); + PLINT n = x.length; + assert( n == y.length, "plpoin(): Arrays must be of same length!" ); + c_plpoin( n, x.ptr, y.ptr, code ); } /* Draws a series of points in 3 space. */ -void plpoin3(PLFLT[] x, PLFLT[] y, PLFLT[] z, PLINT code) +void plpoin3( PLFLT[] x, PLFLT[] y, PLFLT[] z, PLINT code ) { - PLINT n=x.length; - assert(n==y.length, "plpoin3(): Arrays must be of same length!"); - assert(n==z.length, "plpoin3(): Arrays must be of same length!"); - c_plpoin3(n, x.ptr, y.ptr, z.ptr, code); + PLINT n = x.length; + assert( n == y.length, "plpoin3(): Arrays must be of same length!" ); + assert( n == z.length, "plpoin3(): Arrays must be of same length!" ); + c_plpoin3( n, x.ptr, y.ptr, z.ptr, code ); } /* Draws a polygon in 3 space. */ -void plpoly3(PLFLT[] x, PLFLT[] y, PLFLT[] z, PLBOOL[] draw, PLBOOL ifcc) +void plpoly3( PLFLT[] x, PLFLT[] y, PLFLT[] z, PLBOOL[] draw, PLBOOL ifcc ) { - PLINT n=x.length; - assert(n==y.length, "plpoly3(): Arrays must be of same length!"); - assert(n==z.length, "plpoly3(): Arrays must be of same length!"); - assert(n-1==draw.length, "plpoly3(): Array draw must be of same length then other arrays minus 1!"); - c_plpoly3(n, x.ptr, y.ptr, z.ptr, draw.ptr, ifcc); + PLINT n = x.length; + assert( n == y.length, "plpoly3(): Arrays must be of same length!" ); + assert( n == z.length, "plpoly3(): Arrays must be of same length!" ); + assert( n - 1 == draw.length, "plpoly3(): Array draw must be of same length then other arrays minus 1!" ); + c_plpoly3( n, x.ptr, y.ptr, z.ptr, draw.ptr, ifcc ); } /* Prints out "text" at world cooordinate (x,y). */ -void plptex(PLFLT x, PLFLT y, PLFLT dx, PLFLT dy, PLFLT just, string text) +void plptex( PLFLT x, PLFLT y, PLFLT dx, PLFLT dy, PLFLT just, string text ) { - c_plptex(x, y, dx, dy, just, toStringz(text)); + c_plptex( x, y, dx, dy, just, toStringz( text )); } /* Prints out "text" at world cooordinate (x,y,z). */ -void plptex3(PLFLT wx, PLFLT wy, PLFLT wz, PLFLT dx, PLFLT dy, PLFLT dz, - PLFLT sx, PLFLT sy, PLFLT sz, PLFLT just, string text) +void plptex3( PLFLT wx, PLFLT wy, PLFLT wz, PLFLT dx, PLFLT dy, PLFLT dz, + PLFLT sx, PLFLT sy, PLFLT sz, PLFLT just, string text ) { - c_plptex3(wx, wy, wz, dx, dy, dz, sx, sy, sz, just, toStringz(text)); + c_plptex3( wx, wy, wz, dx, dy, dz, sx, sy, sz, just, toStringz( text )); } /* Set the colors for color table 0 from a cmap0 file */ -void plspal0(string filename) +void plspal0( string filename ) { - c_plspal0(toStringz(filename)); + c_plspal0( toStringz( filename )); } /* Set the colors for color table 1 from a cmap1 file */ -void plspal1(string filename, PLBOOL interpolate) +void plspal1( string filename, PLBOOL interpolate ) { - c_plspal1(toStringz(filename), interpolate); + c_plspal1( toStringz( filename ), interpolate ); } /* Set color map 0 colors by 8 bit RGB values */ -void plscmap0(PLINT[] r, PLINT[] g, PLINT[] b) +void plscmap0( PLINT[] r, PLINT[] g, PLINT[] b ) { - PLINT ncol0=r.length; - assert(ncol0==g.length, "plscmap0(): Arrays must be of same length!"); - assert(ncol0==b.length, "plscmap0(): Arrays must be of same length!"); - c_plscmap0(r.ptr, g.ptr, b.ptr, ncol0); + PLINT ncol0 = r.length; + assert( ncol0 == g.length, "plscmap0(): Arrays must be of same length!" ); + assert( ncol0 == b.length, "plscmap0(): Arrays must be of same length!" ); + c_plscmap0( r.ptr, g.ptr, b.ptr, ncol0 ); } /* Set color map 0 colors by 8 bit RGB values and alpha values */ -void plscmap0a(PLINT[] r, PLINT[] g, PLINT[] b, PLFLT[] a) +void plscmap0a( PLINT[] r, PLINT[] g, PLINT[] b, PLFLT[] a ) { - PLINT ncol0=r.length; - assert(ncol0==g.length, "plscmap0a(): Arrays must be of same length!"); - assert(ncol0==b.length, "plscmap0a(): Arrays must be of same length!"); - assert(ncol0==a.length, "plscmap0a(): Arrays must be of same length!"); - c_plscmap0a(r.ptr, g.ptr, b.ptr, a.ptr, ncol0); + PLINT ncol0 = r.length; + assert( ncol0 == g.length, "plscmap0a(): Arrays must be of same length!" ); + assert( ncol0 == b.length, "plscmap0a(): Arrays must be of same length!" ); + assert( ncol0 == a.length, "plscmap0a(): Arrays must be of same length!" ); + c_plscmap0a( r.ptr, g.ptr, b.ptr, a.ptr, ncol0 ); } /* Set color map 1 colors by 8 bit RGB values */ -void plscmap1(PLINT[] r, PLINT[] g, PLINT[] b) +void plscmap1( PLINT[] r, PLINT[] g, PLINT[] b ) { - PLINT ncol1=r.length; - assert(ncol1==g.length, "plscmap1(): Arrays must be of same length!"); - assert(ncol1==b.length, "plscmap1(): Arrays must be of same length!"); - c_plscmap1(r.ptr, g.ptr, b.ptr, ncol1); + PLINT ncol1 = r.length; + assert( ncol1 == g.length, "plscmap1(): Arrays must be of same length!" ); + assert( ncol1 == b.length, "plscmap1(): Arrays must be of same length!" ); + c_plscmap1( r.ptr, g.ptr, b.ptr, ncol1 ); } /* Set color map 1 colors by 8 bit RGB and alpha values */ -void plscmap1a(PLINT[] r, PLINT[] g, PLINT[] b, PLFLT[] a) +void plscmap1a( PLINT[] r, PLINT[] g, PLINT[] b, PLFLT[] a ) { - PLINT ncol1=r.length; - assert(ncol1==g.length, "plscmap1a(): Arrays must be of same length!"); - assert(ncol1==b.length, "plscmap1a(): Arrays must be of same length!"); - assert(ncol1==a.length, "plscmap1a(): Arrays must be of same length!"); - c_plscmap1a(r.ptr, g.ptr, b.ptr, a.ptr, ncol1); + PLINT ncol1 = r.length; + assert( ncol1 == g.length, "plscmap1a(): Arrays must be of same length!" ); + assert( ncol1 == b.length, "plscmap1a(): Arrays must be of same length!" ); + assert( ncol1 == a.length, "plscmap1a(): Arrays must be of same length!" ); + c_plscmap1a( r.ptr, g.ptr, b.ptr, a.ptr, ncol1 ); } /* Set color map 1 colors using a piece-wise linear relationship between */ /* intensity [0,1] (cmap 1 index) and position in HLS or RGB color space. */ -void plscmap1l(PLBOOL itype, PLFLT[] intensity, PLFLT[] coord1, - PLFLT[] coord2, PLFLT[] coord3, PLBOOL[] rev=null) +void plscmap1l( PLBOOL itype, PLFLT[] intensity, PLFLT[] coord1, + PLFLT[] coord2, PLFLT[] coord3, PLBOOL[] rev = null ) { - PLINT npts=intensity.length; - assert(npts==coord1.length, "plscmap1l(): Arrays must be of same length!"); - assert(npts==coord2.length, "plscmap1l(): Arrays must be of same length!"); - assert(npts==coord3.length, "plscmap1l(): Arrays must be of same length!"); - if(rev!=null) { - assert(npts-1==rev.length, "plscmap1l(): Array rev must be of same length then other arrays minus 1!"); - c_plscmap1l(itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, rev.ptr); - } else - c_plscmap1l(itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, null); + PLINT npts = intensity.length; + assert( npts == coord1.length, "plscmap1l(): Arrays must be of same length!" ); + assert( npts == coord2.length, "plscmap1l(): Arrays must be of same length!" ); + assert( npts == coord3.length, "plscmap1l(): Arrays must be of same length!" ); + if ( rev != null ) + { + assert( npts - 1 == rev.length, "plscmap1l(): Array rev must be of same length then other arrays minus 1!" ); + c_plscmap1l( itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, rev.ptr ); + } + else + c_plscmap1l( itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, null ); } /* Set color map 1 colors using a piece-wise linear relationship between */ /* intensity [0,1] (cmap 1 index) and position in HLS or RGB color space. */ /* Will also linear interpolate alpha values. */ -void plscmap1la(PLBOOL itype, PLFLT[] intensity, PLFLT[] coord1, - PLFLT[] coord2, PLFLT[] coord3, PLFLT[] a, PLBOOL[] rev=null) +void plscmap1la( PLBOOL itype, PLFLT[] intensity, PLFLT[] coord1, + PLFLT[] coord2, PLFLT[] coord3, PLFLT[] a, PLBOOL[] rev = null ) { - PLINT npts=intensity.length; - assert(npts==coord1.length, "plscmap1la(): Arrays must be of same length!"); - assert(npts==coord2.length, "plscmap1la(): Arrays must be of same length!"); - assert(npts==coord3.length, "plscmap1la(): Arrays must be of same length!"); - assert(npts==a.length, "plscmap1la(): Arrays must be of same length!"); - if(rev!=null) { - assert(npts-1==rev.length, "plscmap1la(): Array rev must be of same length then other arrays minus 1!"); - c_plscmap1la(itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, a.ptr, rev.ptr); - } else - c_plscmap1la(itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, a.ptr, null); + PLINT npts = intensity.length; + assert( npts == coord1.length, "plscmap1la(): Arrays must be of same length!" ); + assert( npts == coord2.length, "plscmap1la(): Arrays must be of same length!" ); + assert( npts == coord3.length, "plscmap1la(): Arrays must be of same length!" ); + assert( npts == a.length, "plscmap1la(): Arrays must be of same length!" ); + if ( rev != null ) + { + assert( npts - 1 == rev.length, "plscmap1la(): Array rev must be of same length then other arrays minus 1!" ); + c_plscmap1la( itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, a.ptr, rev.ptr ); + } + else + c_plscmap1la( itype, npts, intensity.ptr, coord1.ptr, coord2.ptr, coord3.ptr, a.ptr, null ); } /* Set the device (keyword) name */ -void plsdev(string devname) +void plsdev( string devname ) { - c_plsdev(toStringz(devname)); + c_plsdev( toStringz( devname )); } - + /* Set the output file name. */ -void plsfnam(string fnam) +void plsfnam( string fnam ) { - c_plsfnam(toStringz(fnam)); + c_plsfnam( toStringz( fnam )); } /* Shade region. */ -void plshade(PLFLT[][] a, def_func defined, PLFLT left, PLFLT right, - PLFLT bottom, PLFLT top, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, - PLFLT sh_color, PLINT sh_width, PLINT min_color, PLINT min_width, PLINT max_color, - PLINT max_width, PLBOOL rectangular, - pltr_func pltr=null, PLPointer pltr_data=null) +void plshade( PLFLT[][] a, def_func defined, PLFLT left, PLFLT right, + PLFLT bottom, PLFLT top, PLFLT shade_min, PLFLT shade_max, PLINT sh_cmap, + PLFLT sh_color, PLINT sh_width, PLINT min_color, PLINT min_width, PLINT max_color, + PLINT max_width, PLBOOL rectangular, + pltr_func pltr = null, PLPointer pltr_data = null ) { - PLINT nx=a.length; - PLINT ny=a[0].length; - - c_plshade(convert_array(a), nx, ny, defined, left, right, bottom, top, shade_min, shade_max, sh_cmap, - sh_color, sh_width, min_color, min_width, max_color, max_width, &c_plfill, - rectangular, pltr, pltr_data); + PLINT nx = a.length; + PLINT ny = a[0].length; + + c_plshade( convert_array( a ), nx, ny, defined, left, right, bottom, top, shade_min, shade_max, sh_cmap, + sh_color, sh_width, min_color, min_width, max_color, max_width, &c_plfill, + rectangular, pltr, pltr_data ); } -void plshades(PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, - PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, - PLBOOL rectangular, pltr_func pltr=null, PLPointer pltr_data=null) +void plshades( PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, + PLBOOL rectangular, pltr_func pltr = null, PLPointer pltr_data = null ) { - PLINT nx=a.length; - PLINT ny=a[0].length; + PLINT nx = a.length; + PLINT ny = a[0].length; - c_plshades(convert_array(a), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, - fill_width, cont_color, cont_width, &c_plfill, rectangular, pltr, pltr_data); + c_plshades( convert_array( a ), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, + fill_width, cont_color, cont_width, &c_plfill, rectangular, pltr, pltr_data ); } -void plshades(PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, - PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, - PLBOOL rectangular, ref PLcGrid cgrid) +void plshades( PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, + PLBOOL rectangular, ref PLcGrid cgrid ) { - PLINT nx=a.length; - PLINT ny=a[0].length; + PLINT nx = a.length; + PLINT ny = a[0].length; - c_PLcGrid c; - c.xg = cgrid.xg.ptr; - c.nx = cgrid.xg.length; - c.yg = cgrid.yg.ptr; - c.ny = cgrid.yg.length; - c.zg = cgrid.zg.ptr; - c.nz = cgrid.zg.length; - - c_plshades(convert_array(a), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, - fill_width, cont_color, cont_width, &c_plfill, rectangular, &pltr1, &c); + c_PLcGrid c; + c.xg = cgrid.xg.ptr; + c.nx = cgrid.xg.length; + c.yg = cgrid.yg.ptr; + c.ny = cgrid.yg.length; + c.zg = cgrid.zg.ptr; + c.nz = cgrid.zg.length; + + c_plshades( convert_array( a ), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, + fill_width, cont_color, cont_width, &c_plfill, rectangular, &pltr1, &c ); } -void plshades(PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, - PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, - PLBOOL rectangular, ref PLcGrid2 cgrid2) +void plshades( PLFLT[][] a, def_func defined, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT[] clevel, PLINT fill_width, PLINT cont_color, PLINT cont_width, + PLBOOL rectangular, ref PLcGrid2 cgrid2 ) { - PLINT nx=a.length; - PLINT ny=a[0].length; + PLINT nx = a.length; + PLINT ny = a[0].length; - c_PLcGrid2 c2; - c2.xg = convert_array(cgrid2.xg); - c2.yg = convert_array(cgrid2.yg); - c2.zg = convert_array(cgrid2.zg); - c2.nx = cgrid2.xg.length; - c2.ny = cgrid2.xg[0].length; - if(cgrid2.yg) { - assert(c2.nx==cgrid2.yg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.yg[0].length, "plcont(): Arrays must be of same length!"); - } - if(cgrid2.zg) { - assert(c2.nx==cgrid2.zg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.zg[0].length, "plcont(): Arrays must be of same length!"); - } + c_PLcGrid2 c2; + c2.xg = convert_array( cgrid2.xg ); + c2.yg = convert_array( cgrid2.yg ); + c2.zg = convert_array( cgrid2.zg ); + c2.nx = cgrid2.xg.length; + c2.ny = cgrid2.xg[0].length; + if ( cgrid2.yg ) + { + assert( c2.nx == cgrid2.yg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.yg[0].length, "plcont(): Arrays must be of same length!" ); + } + if ( cgrid2.zg ) + { + assert( c2.nx == cgrid2.zg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.zg[0].length, "plcont(): Arrays must be of same length!" ); + } - c_plshades(convert_array(a), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, - fill_width, cont_color, cont_width, &c_plfill, rectangular, &pltr2, &c2); + c_plshades( convert_array( a ), nx, ny, defined, xmin, xmax, ymin, ymax, clevel.ptr, clevel.length, + fill_width, cont_color, cont_width, &c_plfill, rectangular, &pltr2, &c2 ); } /* Initialize PLplot, passing the device name and windows/page settings. */ -void plstart(string devname, PLINT nx, PLINT ny) +void plstart( string devname, PLINT nx, PLINT ny ) { - c_plstart(toStringz(devname), nx, ny); + c_plstart( toStringz( devname ), nx, ny ); } /* Create 1d stripchart */ -void plstripc(PLINT* id, string xspec, string yspec, PLFLT xmin, PLFLT xmax, PLFLT xjump, - PLFLT ymin, PLFLT ymax, PLFLT xlpos, PLFLT ylpos, PLBOOL y_ascl, PLBOOL acc, - PLINT colbox, PLINT collab, PLINT[] colline, PLINT[] styline, string[] legline, - string labx, string laby, string labtop) +void plstripc( PLINT* id, string xspec, string yspec, PLFLT xmin, PLFLT xmax, PLFLT xjump, + PLFLT ymin, PLFLT ymax, PLFLT xlpos, PLFLT ylpos, PLBOOL y_ascl, PLBOOL acc, + PLINT colbox, PLINT collab, PLINT[] colline, PLINT[] styline, string[] legline, + string labx, string laby, string labtop ) { - assert(4==colline.length, "plstripc(): Arrays must be of length 4!"); - assert(4==styline.length, "plstripc(): Arrays must be of length 4!"); - assert(4==legline.length, "plstripc(): Arrays must be of length 4!"); - - char*[4] leglinez; - for(int i=0; i<4; i++) { - leglinez[i] = toStringz(legline[i]); - } - - c_plstripc(id, toStringz(xspec), toStringz(yspec), xmin, xmax, xjump, ymin, ymax, - xlpos, ylpos, y_ascl, acc, colbox, collab, colline.ptr, styline.ptr, leglinez.ptr, - toStringz(labx), toStringz(laby), toStringz(labtop)); + assert( 4 == colline.length, "plstripc(): Arrays must be of length 4!" ); + assert( 4 == styline.length, "plstripc(): Arrays must be of length 4!" ); + assert( 4 == legline.length, "plstripc(): Arrays must be of length 4!" ); + + char*[4] leglinez; + for ( int i = 0; i < 4; i++ ) + { + leglinez[i] = toStringz( legline[i] ); + } + + c_plstripc( id, toStringz( xspec ), toStringz( yspec ), xmin, xmax, xjump, ymin, ymax, + xlpos, ylpos, y_ascl, acc, colbox, collab, colline.ptr, styline.ptr, leglinez.ptr, + toStringz( labx ), toStringz( laby ), toStringz( labtop )); } /* plots a 2d image (or a matrix too large for plshade() ) */ -void plimagefr(PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, - PLFLT zmin, PLFLT zmax, PLFLT valuemin, PLFLT valuemax, - pltr_func pltr=null, PLPointer pltr_data=null) +void plimagefr( PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT valuemin, PLFLT valuemax, + pltr_func pltr = null, PLPointer pltr_data = null ) { - PLINT nx=idata.length; - PLINT ny=idata[0].length; + PLINT nx = idata.length; + PLINT ny = idata[0].length; - c_plimagefr(convert_array(idata), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, - valuemin, valuemax, pltr, pltr_data); + c_plimagefr( convert_array( idata ), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, + valuemin, valuemax, pltr, pltr_data ); } /* plots a 2d image (or a matrix too large for plshade() ) */ -void plimagefr(PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, - PLFLT zmin, PLFLT zmax, PLFLT valuemin, PLFLT valuemax, PLcGrid cgrid) +void plimagefr( PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT valuemin, PLFLT valuemax, PLcGrid cgrid ) { - PLINT nx=idata.length; - PLINT ny=idata[0].length; + PLINT nx = idata.length; + PLINT ny = idata[0].length; - c_PLcGrid c; - c.xg = cgrid.xg.ptr; - c.nx = cgrid.xg.length; - c.yg = cgrid.yg.ptr; - c.ny = cgrid.yg.length; - c.zg = cgrid.zg.ptr; - c.nz = cgrid.zg.length; - - c_plimagefr(convert_array(idata), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, - valuemin, valuemax, &pltr1, &c); + c_PLcGrid c; + c.xg = cgrid.xg.ptr; + c.nx = cgrid.xg.length; + c.yg = cgrid.yg.ptr; + c.ny = cgrid.yg.length; + c.zg = cgrid.zg.ptr; + c.nz = cgrid.zg.length; + + c_plimagefr( convert_array( idata ), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, + valuemin, valuemax, &pltr1, &c ); } /* plots a 2d image (or a matrix too large for plshade() ) */ -void plimagefr(PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, - PLFLT zmin, PLFLT zmax, PLFLT valuemin, PLFLT valuemax, PLcGrid2 cgrid2) +void plimagefr( PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT valuemin, PLFLT valuemax, PLcGrid2 cgrid2 ) { - PLINT nx=idata.length; - PLINT ny=idata[0].length; + PLINT nx = idata.length; + PLINT ny = idata[0].length; - c_PLcGrid2 c2; - c2.xg = convert_array(cgrid2.xg); - c2.yg = convert_array(cgrid2.yg); - c2.zg = convert_array(cgrid2.zg); - c2.nx = cgrid2.xg.length; - c2.ny = cgrid2.xg[0].length; - if(cgrid2.yg) { - assert(c2.nx==cgrid2.yg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.yg[0].length, "plcont(): Arrays must be of same length!"); - } - if(cgrid2.zg) { - assert(c2.nx==cgrid2.zg.length, "plcont(): Arrays must be of same length!"); - assert(c2.ny==cgrid2.zg[0].length, "plcont(): Arrays must be of same length!"); - } + c_PLcGrid2 c2; + c2.xg = convert_array( cgrid2.xg ); + c2.yg = convert_array( cgrid2.yg ); + c2.zg = convert_array( cgrid2.zg ); + c2.nx = cgrid2.xg.length; + c2.ny = cgrid2.xg[0].length; + if ( cgrid2.yg ) + { + assert( c2.nx == cgrid2.yg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.yg[0].length, "plcont(): Arrays must be of same length!" ); + } + if ( cgrid2.zg ) + { + assert( c2.nx == cgrid2.zg.length, "plcont(): Arrays must be of same length!" ); + assert( c2.ny == cgrid2.zg[0].length, "plcont(): Arrays must be of same length!" ); + } - c_plimagefr(convert_array(idata), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, - valuemin, valuemax, &pltr2, &c2); + c_plimagefr( convert_array( idata ), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, + valuemin, valuemax, &pltr2, &c2 ); } /* plots a 2d image (or a matrix too large for plshade() ) - colors - automatically scaled */ -void plimage(PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, - PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax) + * automatically scaled */ +void plimage( PLFLT[][] idata, PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax ) { - PLINT nx=idata.length; - PLINT ny=idata[0].length; + PLINT nx = idata.length; + PLINT ny = idata[0].length; - c_plimage(convert_array(idata), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, Dxmin, Dxmax, - Dymin, Dymax); + c_plimage( convert_array( idata ), nx, ny, xmin, xmax, ymin, ymax, zmin, zmax, Dxmin, Dxmax, + Dymin, Dymax ); } /* Set up a new line style */ -void plstyl(PLINT[] mark, PLINT[] space) +void plstyl( PLINT[] mark, PLINT[] space ) { - PLINT nms=mark.length; - assert(nms==space.length, "plstyl(): Arrays must be of same length!"); - c_plstyl(nms, mark.ptr, space.ptr); + PLINT nms = mark.length; + assert( nms == space.length, "plstyl(): Arrays must be of same length!" ); + c_plstyl( nms, mark.ptr, space.ptr ); } /* Plots the 3d surface representation of the function z[x][y]. */ -void plsurf3d(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel=null) +void plsurf3d( PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel = null ) { - PLINT nx=z.length; - PLINT ny=z[0].length; - assert(nx==x.length, "plsurf3d(): Arrays must be of same length!"); - assert(ny==y.length, "plsurf3d(): Arrays must be of same length!"); - - if(clevel) - c_plsurf3d(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length); - else - c_plsurf3d(x.ptr, y.ptr, convert_array(z), nx, ny, opt, null, 0); + PLINT nx = z.length; + PLINT ny = z[0].length; + assert( nx == x.length, "plsurf3d(): Arrays must be of same length!" ); + assert( ny == y.length, "plsurf3d(): Arrays must be of same length!" ); + + if ( clevel ) + c_plsurf3d( x.ptr, y.ptr, convert_array( z ), nx, ny, opt, clevel.ptr, clevel.length ); + else + c_plsurf3d( x.ptr, y.ptr, convert_array( z ), nx, ny, opt, null, 0 ); } /* Plots the 3d surface representation of the function z[x][y] with y * index limits. */ -void plsurf3dl(PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel, - PLINT ixstart, PLINT ixn, PLINT[] indexymin, PLINT[] indexymax) +void plsurf3dl( PLFLT[] x, PLFLT[] y, PLFLT[][] z, PLINT opt, PLFLT[] clevel, + PLINT ixstart, PLINT ixn, PLINT[] indexymin, PLINT[] indexymax ) { - PLINT nx=z.length; - PLINT ny=z[0].length; - assert(nx==x.length, "plsurf3d(): Arrays must be of same length!"); - assert(ny==y.length, "plsurf3d(): Arrays must be of same length!"); + PLINT nx = z.length; + PLINT ny = z[0].length; + assert( nx == x.length, "plsurf3d(): Arrays must be of same length!" ); + assert( ny == y.length, "plsurf3d(): Arrays must be of same length!" ); - c_plsurf3dl(x.ptr, y.ptr, convert_array(z), nx, ny, opt, clevel.ptr, clevel.length, - ixstart, ixn, indexymin.ptr, indexymax.ptr); + c_plsurf3dl( x.ptr, y.ptr, convert_array( z ), nx, ny, opt, clevel.ptr, clevel.length, + ixstart, ixn, indexymin.ptr, indexymax.ptr ); } /* Plots array y against x for n points using Hershey symbol "code" */ -void plsym(PLFLT[] x, PLFLT[] y, PLINT code) +void plsym( PLFLT[] x, PLFLT[] y, PLINT code ) { - PLINT n=x.length; - assert(n==y.length, "plsym(): Arrays must be of same length!"); - c_plsym(n, x.ptr, y.ptr, code); + PLINT n = x.length; + assert( n == y.length, "plsym(): Arrays must be of same length!" ); + c_plsym( n, x.ptr, y.ptr, code ); } /* Set the format for date / time labels */ -void pltimefmt(string fmt) +void pltimefmt( string fmt ) { - c_pltimefmt(toStringz(fmt)); + c_pltimefmt( toStringz( fmt )); } /*--------------------------------------------------------------------------* * Functions for use from C or C++ only -\*--------------------------------------------------------------------------*/ + \*--------------------------------------------------------------------------*/ /* Returns a list of file-oriented device names and their menu strings */ //void plgFileDevs(char ***p_menustr, char ***p_devname, int *p_ndev); @@ -822,10 +836,10 @@ /* Process input strings, treating them as an option and argument pair. */ /* The first is for the external API, the second the work routine declared - here for backward compatibilty. */ -int plsetopt(string opt, string optarg) + * here for backward compatibilty. */ +int plsetopt( string opt, string optarg ) { - return c_plsetopt(toStringz(opt), toStringz(optarg)); + return c_plsetopt( toStringz( opt ), toStringz( optarg )); } /* Miscellaneous */ @@ -853,9 +867,9 @@ //PLFLT plGetFlt(char *s); /* Find the maximum and minimum of a 2d matrix allocated with plAllc2dGrid(). */ -void plMinMax2dGrid(PLFLT[][] f, out PLFLT fmax, out PLFLT fmin) +void plMinMax2dGrid( PLFLT[][] f, out PLFLT fmax, out PLFLT fmin ) { - plMinMax2dGrid(convert_array(f), f.length, f[0].length, &fmax, &fmin); + plMinMax2dGrid( convert_array( f ), f.length, f[0].length, &fmax, &fmin ); } /* Wait for graphics input event and translate to world coordinates */ @@ -866,14 +880,14 @@ -extern (C): +extern ( C ) : alias double PLFLT; /* This is apparently portable if stdint.h exists. */ /* A reasonable back-up in case stdint.h does not exist on the platform. */ alias uint PLUNICODE; -alias int PLINT; +alias int PLINT; /* For identifying logical (boolean) arguments */ alias PLINT PLBOOL; @@ -883,48 +897,48 @@ /*--------------------------------------------------------------------------* * Complex data types and other good stuff -\*--------------------------------------------------------------------------*/ + \*--------------------------------------------------------------------------*/ /* Switches for escape function call. */ /* Some of these are obsolete but are retained in order to process - old metafiles. */ + * old metafiles. */ -const PLESC_SET_RGB = 1; -const PLESC_ALLOC_NCOL = 2; -const PLESC_SET_LPB = 3; -const PLESC_EXPOSE = 4; -const PLESC_RESIZE = 5; -const PLESC_REDRAW = 6; -const PLESC_TEXT = 7; -const PLESC_GRAPH = 8; -const PLESC_FILL = 9; -const PLESC_DI = 10; -const PLESC_FLUSH = 11; -const PLESC_EH = 12; -const PLESC_GETC = 13; -const PLESC_SWIN = 14; +const PLESC_SET_RGB = 1; +const PLESC_ALLOC_NCOL = 2; +const PLESC_SET_LPB = 3; +const PLESC_EXPOSE = 4; +const PLESC_RESIZE = 5; +const PLESC_REDRAW = 6; +const PLESC_TEXT = 7; +const PLESC_GRAPH = 8; +const PLESC_FILL = 9; +const PLESC_DI = 10; +const PLESC_FLUSH = 11; +const PLESC_EH = 12; +const PLESC_GETC = 13; +const PLESC_SWIN = 14; const PLESC_DOUBLEBUFFERING = 15; -const PLESC_XORMOD = 16; +const PLESC_XORMOD = 16; const PLESC_SET_COMPRESSION = 17; -const PLESC_CLEAR = 18; -const PLESC_DASH = 19; -const PLESC_HAS_TEXT = 20; -const PLESC_IMAGE = 21; -const PLESC_IMAGEOPS = 22; -const PLESC_PL2DEVCOL = 23; -const PLESC_DEV2PLCOL = 24; -const PLESC_SETBGFG = 25; -const PLESC_DEVINIT = 26; +const PLESC_CLEAR = 18; +const PLESC_DASH = 19; +const PLESC_HAS_TEXT = 20; +const PLESC_IMAGE = 21; +const PLESC_IMAGEOPS = 22; +const PLESC_PL2DEVCOL = 23; +const PLESC_DEV2PLCOL = 24; +const PLESC_SETBGFG = 25; +const PLESC_DEVINIT = 26; /* image operations */ const ZEROW2B = 1; const ZEROW2D = 2; -const ONEW2B = 3; -const ONEW2D = 4; +const ONEW2B = 3; +const ONEW2D = 4; /* Window parameter tags */ const PLSWIN_DEVICE = 1; -const PLSWIN_WORLD = 2; +const PLSWIN_WORLD = 2; /* Axis label tags */ const PL_X_AXIS = 1; /* The x-axis */ @@ -934,59 +948,59 @@ /* PLplot Option table & support constants */ /* Option-specific settings */ -const PL_OPT_ENABLED = 0x0001; -const PL_OPT_ARG = 0x0002; -const PL_OPT_NODELETE = 0x0004; +const PL_OPT_ENABLED = 0x0001; +const PL_OPT_ARG = 0x0002; +const PL_OPT_NODELETE = 0x0004; const PL_OPT_INVISIBLE = 0x0008; -const PL_OPT_DISABLED = 0x0010; +const PL_OPT_DISABLED = 0x0010; /* Option-processing settings -- mutually exclusive */ -const PL_OPT_FUNC = 0x0100; -const PL_OPT_BOOL = 0x0200; -const PL_OPT_INT = 0x0400; -const PL_OPT_FLOAT = 0x0800; +const PL_OPT_FUNC = 0x0100; +const PL_OPT_BOOL = 0x0200; +const PL_OPT_INT = 0x0400; +const PL_OPT_FLOAT = 0x0800; const PL_OPT_STRING = 0x1000; /* Global mode settings */ /* These override per-option settings */ const PL_PARSE_PARTIAL = 0x0000; -const PL_PARSE_FULL = 0x0001; -const PL_PARSE_QUIET = 0x0002; +const PL_PARSE_FULL = 0x0001; +const PL_PARSE_QUIET = 0x0002; /* processing */ -const PL_PARSE_NODELETE = 0x0004; -const PL_PARSE_SHOWALL = 0x0008; -const PL_PARSE_OVERRIDE = 0x0010; +const PL_PARSE_NODELETE = 0x0004; +const PL_PARSE_SHOWALL = 0x0008; +const PL_PARSE_OVERRIDE = 0x0010; const PL_PARSE_NOPROGRAM = 0x0020; -const PL_PARSE_NODASH = 0x0040; -const PL_PARSE_SKIP = 0x0080; +const PL_PARSE_NODASH = 0x0040; +const PL_PARSE_SKIP = 0x0080; /* FCI (font characterization integer) related constants. */ -const PL_FCI_MARK = 0x80000000; -const PL_FCI_IMPOSSIBLE = 0x00000000; +const PL_FCI_MARK = 0x80000000; +const PL_FCI_IMPOSSIBLE = 0x00000000; const PL_FCI_HEXDIGIT_MASK = 0xf; const PL_FCI_HEXPOWER_MASK = 0x7; /* These define hexpower values corresponding to each font attribute. */ const PL_FCI_HEXPOWER_IMPOSSIBLE = 0xf; const PL_FCI_FAMILY = 0x0; -const PL_FCI_STYLE = 0x1; +const PL_FCI_STYLE = 0x1; /* These are legal values for font family attribute */ const PL_FCI_WEIGHT = 0x2; -const PL_FCI_SANS = 0x0; -const PL_FCI_SERIF = 0x1; -const PL_FCI_MONO = 0x2; +const PL_FCI_SANS = 0x0; +const PL_FCI_SERIF = 0x1; +const PL_FCI_MONO = 0x2; const PL_FCI_SCRIPT = 0x3; /* These are legal values for font style attribute */ -const PL_FCI_SYMBOL = 0x4; +const PL_FCI_SYMBOL = 0x4; const PL_FCI_UPRIGHT = 0x0; -const PL_FCI_ITALIC = 0x1; +const PL_FCI_ITALIC = 0x1; /* These are legal values for font weight attribute */ -const PL_FCI_MEDIUM = 0x0; -const PL_FCI_BOLD = 0x1; +const PL_FCI_MEDIUM = 0x0; +const PL_FCI_BOLD = 0x1; const PL_FCI_OBLIQUE = 0x2; /* Obsolete names */ @@ -996,10 +1010,10 @@ struct _N1 { char *opt; - int function(char *, char *, void *)handler; + int function( char *, char *, void * ) handler; void *client_data; void *var; - int mode; + int mode; char *syntax; char *desc; } @@ -1011,14 +1025,14 @@ const PL_MAXKEY = 16; struct _N2 { - int type; - uint state; - uint keysym; - uint button; + int type; + uint state; + uint keysym; + uint button; PLINT subwindow; - char [16]string; - int pX; - int pY; + char [16] string; + int pX; + int pY; PLFLT dX; PLFLT dY; PLFLT wX; @@ -1141,7 +1155,7 @@ ubyte g; ubyte b; PLFLT a; - char *name; + char *name; } alias _N9 PLColor; @@ -1154,12 +1168,12 @@ PLFLT s; PLFLT p; PLFLT a; - int rev; + int rev; } alias _N10 PLControlPt; /* A PLBufferingCB is a control block for interacting with devices - that support double buffering. */ + * that support double buffering. */ struct _N11 { @@ -1168,10 +1182,10 @@ } alias _N11 PLBufferingCB; -const PLESC_DOUBLEBUFFERING_ENABLE = 1; -const PLESC_DOUBLEBUFFERING_DISABLE = 2; +const PLESC_DOUBLEBUFFERING_ENABLE = 1; +const PLESC_DOUBLEBUFFERING_DISABLE = 2; -const PLESC_DOUBLEBUFFERING_QUERY = 3; +const PLESC_DOUBLEBUFFERING_QUERY = 3; /*--------------------------------------------------------------------------* * BRAINDEAD-ness * @@ -1219,82 +1233,82 @@ * with either stub routines for the inevitable data conversions, or a * different API. The former is what is used here, but is made far more * difficult in a braindead shared Fortran/C namespace. -\*--------------------------------------------------------------------------*/ + \*----------------------------------------------------------------... [truncated message content] |
From: <ai...@us...> - 2009-12-14 18:06:18
|
Revision: 10719 http://plplot.svn.sourceforge.net/plplot/?rev=10719&view=rev Author: airwin Date: 2009-12-14 18:06:07 +0000 (Mon, 14 Dec 2009) Log Message: ----------- Style tweaks for recent changes. Modified Paths: -------------- trunk/bindings/tcl/tclAPI.c trunk/src/plcore.c Modified: trunk/bindings/tcl/tclAPI.c =================================================================== --- trunk/bindings/tcl/tclAPI.c 2009-12-10 20:18:54 UTC (rev 10718) +++ trunk/bindings/tcl/tclAPI.c 2009-12-14 18:06:07 UTC (rev 10719) @@ -640,7 +640,7 @@ pls_auto_path( Tcl_Interp *interp ) { char *buf, *ptr = NULL, *dn; - int return_code = TCL_OK; + int return_code = TCL_OK; #ifdef DEBUG char *path; #endif @@ -653,7 +653,7 @@ Tcl_SetVar( interp, "dir", TCL_DIR, TCL_GLOBAL_ONLY ); if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR ) { - return_code = TCL_ERROR; + return_code = TCL_ERROR; goto finish; } #ifdef DEBUG @@ -671,7 +671,7 @@ Tcl_SetVar( interp, "dir", ptr, 0 ); if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR ) { - return_code = TCL_ERROR; + return_code = TCL_ERROR; goto finish; } #ifdef DEBUG @@ -690,7 +690,7 @@ Tcl_SetVar( interp, "dir", ptr, 0 ); if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR ) { - return_code = TCL_ERROR; + return_code = TCL_ERROR; goto finish; } #ifdef DEBUG @@ -710,7 +710,7 @@ Tcl_SetVar( interp, "dir", ptr, 0 ); if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR ) { - return_code = TCL_ERROR; + return_code = TCL_ERROR; goto finish; } #ifdef DEBUG @@ -727,14 +727,14 @@ { Tcl_SetResult( interp, "Problems with getcwd in pls_auto_path", TCL_STATIC ); { - return_code = TCL_ERROR; + return_code = TCL_ERROR; goto finish; } } Tcl_SetVar( interp, "dir", buf, 0 ); if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR ) { - return_code = TCL_ERROR; + return_code = TCL_ERROR; goto finish; } /*** see if plserver was invoked in the build tree ***/ @@ -743,7 +743,7 @@ Tcl_SetVar( interp, "dir", BUILD_DIR "/bindings/tk", TCL_GLOBAL_ONLY ); if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR ) { - return_code = TCL_ERROR; + return_code = TCL_ERROR; goto finish; } } Modified: trunk/src/plcore.c =================================================================== --- trunk/src/plcore.c 2009-12-10 20:18:54 UTC (rev 10718) +++ trunk/src/plcore.c 2009-12-14 18:06:07 UTC (rev 10719) @@ -964,7 +964,7 @@ char tmpstring[31]; strncpy( tmpstring, string, 30 ); tmpstring[30] = '\0'; - snprintf( buf, BUFFER_SIZE, "UTF-8 string is malformed: %s%s", + snprintf( buf, BUFFER_SIZE, "UTF-8 string is malformed: %s%s", tmpstring, strlen( string ) > 30 ? "[...]" : "" ); plabort( buf ); return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ai...@us...> - 2009-12-15 22:28:48
|
Revision: 10720 http://plplot.svn.sourceforge.net/plplot/?rev=10720&view=rev Author: airwin Date: 2009-12-15 22:28:41 +0000 (Tue, 15 Dec 2009) Log Message: ----------- Qualify arguments for plP_pointinpolygon. Implement fill_intersection_polygon and ifnotintersect (which fill_intersection_polygon calls), but do not use these experimental functions (which still have issues) to do clipped fills and gradients unless the user sets the cmake option -DUSE_FILL_INTERSECTION_POLYGON=ON. Modified Paths: -------------- trunk/cmake/modules/plplot.cmake trunk/config.h.cmake trunk/include/plplotP.h trunk/src/plfill.c Modified: trunk/cmake/modules/plplot.cmake =================================================================== --- trunk/cmake/modules/plplot.cmake 2009-12-14 18:06:07 UTC (rev 10719) +++ trunk/cmake/modules/plplot.cmake 2009-12-15 22:28:41 UTC (rev 10720) @@ -31,6 +31,12 @@ set(DEFAULT_CMAP1_FILE "cmap1_default.pal") endif(NOT DEFAULT_CMAP1_FILE) +# Set to ON if want to use general fill_intersection_polygon approach +# rather than the traditional code to fill the intersection of a +# polygon with the clipping limits. */ + +option(USE_FILL_INTERSECTION_POLYGON "use fill_intersection_polygon" OFF) + # Need these modules to do subsequent checks. include(CheckIncludeFiles) include(CheckFunctionExists) Modified: trunk/config.h.cmake =================================================================== --- trunk/config.h.cmake 2009-12-14 18:06:07 UTC (rev 10719) +++ trunk/config.h.cmake 2009-12-15 22:28:41 UTC (rev 10720) @@ -282,6 +282,11 @@ /* Define if csa is desired */ #cmakedefine WITH_CSA +/* Define if want to use general fill_intersection_polygon approach + * rather than the traditional code to fill the intersection of a polygon with + * the clipping limits. */ +#cmakedefine USE_FILL_INTERSECTION_POLYGON + /* Define to `char *' if <sys/types.h> does not define. */ #cmakedefine caddr_t Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2009-12-14 18:06:07 UTC (rev 10719) +++ trunk/include/plplotP.h 2009-12-15 22:28:41 UTC (rev 10720) @@ -975,7 +975,8 @@ /* Test whether a point is in a polygon. */ int -plP_pointinpolygon( PLINT n, PLFLT *x, PLFLT *y, PLFLT xp, PLFLT yp ); +plP_pointinpolygon( PLINT n, const PLFLT *x, const PLFLT *y, + PLFLT xp, PLFLT yp ); /* Driver calls */ Modified: trunk/src/plfill.c =================================================================== --- trunk/src/plfill.c 2009-12-14 18:06:07 UTC (rev 10719) +++ trunk/src/plfill.c 2009-12-15 22:28:41 UTC (rev 10720) @@ -26,7 +26,7 @@ #define INSIDE( ix, iy ) ( BETW( ix, xmin, xmax ) && BETW( iy, ymin, ymax )) -#define DTOR 0.0174533 +#define DTOR ( PI / 180. ) #define BINC 50 struct point @@ -36,7 +36,6 @@ static PLINT bufferleng, buffersize, *buffer; /* Static function prototypes */ -/* INDENT OFF */ static int compar( const void *, const void * ); @@ -51,13 +50,23 @@ buildlist( PLINT, PLINT, PLINT, PLINT, PLINT, PLINT, PLINT ); static int -pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ); +pointinpolygon( PLINT n, const PLINT *x, const PLINT *y, PLINT xp, PLINT yp ); static int circulation( PLINT *x, PLINT *y, PLINT npts ); +static void +fill_intersection_polygon( PLINT recursion_depth, PLINT ifclip, + void ( *fill )( short *, short *, PLINT ), + const PLINT *x1, const PLINT *y1, + PLINT i1start, PLINT n1, + const PLINT *x2, const PLINT *y2, + const PLINT *if2, PLINT n2 ); -/* INDENT ON */ +static int +ifnotintersect( PLINT *xintersect, PLINT *yintersect, + PLINT xA1, PLINT yA1, PLINT xA2, PLINT yA2, + PLINT xB1, PLINT yB1, PLINT xB2, PLINT yB2 ); /*----------------------------------------------------------------------*\ * void plfill() @@ -410,6 +419,46 @@ PLINT xmin, PLINT xmax, PLINT ymin, PLINT ymax, void ( *draw )( short *, short *, PLINT )) { + /* Must have at least 3 points and draw() specified */ + if ( npts < 3 || !draw ) return; + +#ifdef USE_FILL_INTERSECTION_POLYGON + PLINT *x1, *y1, i1start = 0, i, im1, n1; + PLINT x2[4] = { xmin, xmax, xmax, xmin }; + PLINT y2[4] = { ymin, ymin, ymax, ymax }; + PLINT if2[4] = { 0, 0, 0, 0 }; + PLINT n2 = 4; + if (( x1 = (PLINT *) malloc( npts * sizeof ( PLINT ))) == NULL ) + { + plexit( "plP_plfclp: Insufficient memory" ); + } + if (( y1 = (PLINT *) malloc( npts * sizeof ( PLINT ))) == NULL ) + { + plexit( "plP_plfclp: Insufficient memory" ); + } + /* Polygon 2 obviously has no dups, but get rid of them in polygon + * 1 if they exist. ToDo: Deal with self-intersecting polygon 1 + * case as well. */ + + im1 = npts - 1; + n1 = 0; + for ( i = 0; i < npts; i++ ) + { + if ( !( x[i] == x[im1] && y[i] == y[im1] )) + { + x1[n1] = x[i]; + y1[n1++] = y[i]; + } + im1 = i; + } + + fill_intersection_polygon( 0, 0, draw, x1, y1, i1start, n1, x2, y2, if2, n2 ); + free( x1 ); + free( y1 ); + return; +} +#else /* USE_FILL_INTERSECTION_POLYGON */ + PLINT i, x1, x2, y1, y2; int iclp = 0, iout = 2; short _xclp[2 * PL_MAXPOLY + 2], _yclp[2 * PL_MAXPOLY + 2]; @@ -426,8 +475,6 @@ int inside_rb; int inside_ru; -/* Must have at least 3 points and draw() specified */ - if ( npts < 3 || !draw ) return; if ( npts < PL_MAXPOLY ) { @@ -442,7 +489,6 @@ plexit( "plP_plfclp: Insufficient memory" ); } } - inside_lb = pointinpolygon( npts, x, y, xmin, ymin ); inside_lu = pointinpolygon( npts, x, y, xmin, ymax ); inside_rb = pointinpolygon( npts, x, y, xmax, ymin ); @@ -600,9 +646,9 @@ } } -/* Limit case - all vertices are outside of bounding box. So just fill entire - * box, *if* the bounding box is completely encircled. - */ + /* Limit case - all vertices are outside of bounding box. So just fill entire + * box, *if* the bounding box is completely encircled. + */ if ( iclp == 0 ) { if ( inside_lb ) @@ -624,7 +670,7 @@ } } -/* Now handle cases where fill polygon intersects two sides of the box */ + /* Now handle cases where fill polygon intersects two sides of the box */ if ( iclp >= 2 ) { @@ -806,11 +852,11 @@ } } -/* Check for the case that only one side has been crossed - * (AM) Just checking a single point turns out not to be - * enough, apparently the crossed_*1 and crossed_*2 variables - * are not quite what I expected. - */ + /* Check for the case that only one side has been crossed + * (AM) Just checking a single point turns out not to be + * enough, apparently the crossed_*1 and crossed_*2 variables + * are not quite what I expected. + */ if ( inside_lb + inside_rb + inside_lu + inside_ru == 4 ) { int dir = circulation( x, y, npts ); @@ -910,7 +956,7 @@ } } -/* Draw the sucker */ + /* Draw the sucker */ if ( iclp >= 3 ) ( *draw )( xclp, yclp, iclp ); @@ -920,6 +966,7 @@ free( yclp ); } } +#endif /* USE_FILL_INTERSECTION_POLYGON */ /*----------------------------------------------------------------------*\ * int circulation() @@ -948,9 +995,9 @@ circulation( PLINT *x, PLINT *y, PLINT npts ) { PLFLT xproduct; - int direction = 0; + int direction = 0; PLFLT x1, y1, x2, y2, x3, y3; - int i; + int i; xproduct = 0.0; x1 = x[0]; @@ -976,9 +1023,9 @@ \*----------------------------------------------------------------------*/ static int -pointinpolygon( PLINT n, PLINT *x, PLINT *y, PLINT xp, PLINT yp ) +pointinpolygon( PLINT n, const PLINT *x, const PLINT *y, PLINT xp, PLINT yp ) { - int i, return_value; + int i, return_value; PLFLT *xflt, *yflt; if (( xflt = (PLFLT *) malloc( n * sizeof ( PLFLT ))) == NULL ) { @@ -1011,10 +1058,10 @@ \*----------------------------------------------------------------------*/ int -plP_pointinpolygon( PLINT n, PLFLT *x, PLFLT *y, PLFLT xp, PLFLT yp ) +plP_pointinpolygon( PLINT n, const PLFLT *x, const PLFLT *y, PLFLT xp, PLFLT yp ) { - int i; - int count_crossings; + int i; + int count_crossings; PLFLT x1, y1, x2, y2, xout, yout, xmax; PLFLT xvp, yvp, xvv, yvv, xv1, yv1, xv2, yv2; PLFLT inprod1, inprod2; @@ -1106,3 +1153,504 @@ return ( count_crossings % 2 ); } + +/* Fill intersection of two simple (not self-intersecting) polygons. + * There must be an even number of edge intersections between the two + * polygons (ignoring vertex intersections which touch, but do not cross). + * Eliminate those intersection pairs by recursion (calling the same + * routine again with either the first or second polygon split between + * the two intersecting edges into two independent second polygons.) + * Once the recursion has eliminated all intersecting edges, fill or + * not using the appropriate polygon depending on whether the first + * and second polygons are identical or whether one of them is + * entirely inside the other of them. If ifclip is true, the fill + * step will consist of another recursive call to the routine with + * ifclip false and the second polygon set to the clip rectangle. + * N.B. it is the calling routine's responsibility to insure the two + * polygons are not self-intersecting and do not have duplicate points. */ + +/* Consider the intersections between the first and second + * polygons (including the possibility of multiple intersections per edge of + * the first polygon). The total number of such intersections must be even. + * Solve for the first pair of intersections (if any) and simplify the problem + * by recursively calling the same routine twice with the same first polygon + * and two modified second polygons consisting of the left-hand segment of the + * second polygon + two intersection points and the right-hand segment of the + * second polygon + two intersection points. Note that for the recursive call + * the vertices that were intersection points should not generate new + * intersections with the first unchanging polygon because points on the + * perimeter of polygons are always considered to be outside it. However, due + * to integer truncation and other numerical errors I doubt we can guaranteed + * that numerically in all cases. So we set up a logical array that drops + * segments from the intersection test that are already bounded by + * intersections generated higher in the recursion stack. The result + * of this recursion is deep in the recursion stack you finally end up + * considering the case of the original first polygon and a modified second + * polygon that does not intersect with it at all. + * + * + * . Solve that simple case. Check for identical polygons (taking into account + * the possibilities of different starting points and different directions + * traversing the perimeter), and if so, do a fill of the first polygon (to be + * specific) in that case. If not identical, then do one testinpolygon call to + * decide if the second polygon is totally inside the first. If so, fill the + * second polygon. If not, use one additional testinpolygon call to decide if + * the first polygon is totally inside the second, and if so, fill the first + * polygon. + * + * . Carry a clip flag as part of the recursion, and for the simple case above + * with the flag true, start the recursion all over again (with the clip flag + * false) with the "filling" polygon as the first polygon, and the clip + * rectangle as the the second. + * + * + * Find innermost polygon of (x1,y1) and (x2, y2) for the purposes of + * filling. The number of vertices is returned, and the resulting + * inner (xinner, yinner) polygon calculated for that number of + * vertices. A zero is returned as an error code if the number of + * inner polygon vertices exceeds max_ninner (which should be set + * externally to the size allocated externally for xinner, yinner). A + * zero is also returned if n1 < 3 or (n2 < 3 && n2 != -2). (Note + * that n2 = -2 signals the special case when the second polygon is a + * rectangle.) */ + +#define MAX_RECURSION_DEPTH 10 +void +fill_intersection_polygon( PLINT recursion_depth, PLINT ifclip, + void ( *fill )( short *, short *, PLINT ), + const PLINT *x1, const PLINT *y1, + PLINT i1start, PLINT n1, + const PLINT *x2, const PLINT *y2, + const PLINT *if2, PLINT n2 ) +{ + PLINT i1, i1m1, i1wrap, i1wraplast, + i2, i2m1, i2wrap, i2wraplast, + kk, kkstart1, kkstart21, kkstart22, + k, kstart, range1, range21, range22, nintersect, + nsplit1, nsplit2; + PLINT xintersect[2], yintersect[2], ifintersect; + PLINT *xsplit1, *ysplit1, *ifsplit1, + *xsplit2, *ysplit2, *ifsplit2; + PLINT ifill, nfill = 0; + const PLINT *xfiller, *yfiller; + short *xfill, *yfill; + + if ( recursion_depth > MAX_RECURSION_DEPTH ) + { + plwarn( "fill_intersection_polygon: Recursion_depth too large. " + "Probably an internal error figuring out intersections. " ); + return; + } + + if ( n1 < 3 ) + { + plwarn( "fill_intersection_polygon: Internal error; n1 < 3." ); + return; + } + + if ( n2 < 3 ) + { + plwarn( "fill_intersection_polygon: Internal error; n2 < 3." ); + return; + } + + if ( i1start < 0 || i1start >= n1 ) + { + plwarn( "fill_intersection_polygon: invalid i1start." ); + return; + } + + i1m1 = i1start - 1; + if ( i1m1 <= 0 ) + i1m1 = n1 - 1; + + for ( i1 = i1start; i1 < n1; i1++ ) + { + if ( x1[i1] == x1[i1m1] && y1[i1] == y1[i1m1] ) + break; + i1m1 = i1; + } + + if ( i1 < n1 ) + { + plwarn( "fill_intersection_polygon: Internal error; i1 < n1." ); + return; + } + + i2m1 = n2 - 1; + for ( i2 = 0; i2 < n2; i2++ ) + { + if ( x2[i2] == x2[i2m1] && y2[i2] == y2[i2m1] ) + break; + i2m1 = i2; + } + + if ( i2 < n2 ) + { + plwarn( "fill_intersection_polygon: Internal error; i < n2." ); + return; + } + + /* + * + * Follow polygon 1 (checking intersections with polygon 2 for each + * segment of polygon 1) until you have accumulated two + * intersections with polygon 2. Here is an ascii-art illustration + * of the situation. + * + * + * 2???2 + * + * 2 2 + * + * --- 1 1 + * 1 2 1 1 ... + * x + * 1 + * x + * 2 + * 1 1 + * 1 + * 2 + * 2 + * 2???2 + * + * + * "1" marks polygon 1 vertices, "2" marks polygon 2 vertices, "x" + * marks the intersections, "---" stands for part of polygon 1 + * that has been previously searched for all possible intersections + * from index 0, and "..." means polygon 1 continues + * with more potential intersections both above or below this diagram + * before it finally hooks back to connect with the index 0 vertex. + * "2???2" stands for parts of polygon 2 that must connect with each other + * (since the polygon 1 path between the two intersections is + * known to be free of intersections.) + * + * Polygon 2 is split at the boundary defined by the two + * intersections and all (in this case three) polygon 1 vertices + * between the two intersections for the next recursion level. We + * absolutely know for that boundary that no more intersections can + * occur (both polygon 1 and polygon 2 are guaranteed not to + * self-intersect) so we mark the status of those vertices with that + * information so those polygon 2 split vertices will not be used to + * search for further intersections at deeper recursion levels. + * Note, we know nothing about whether the remaining "2???2" parts of the + * split polygon 2 intersect with polygon 1 or not so those will + * continued to be searched at deeper recursion levels. At the same + * time, we absolutely know that the part of polygon 1 to the left of + * rightmost x down to and including index 0 cannot yield more + * intersections with any split of polygon 2 so we adjust the lower + * limit of polygon 1 to be used for intersection searches at deeper + * recursion levels. The result should be that at sufficiently deep + * recursion depth we always end up with the case that there are no + * intersections to be found between polygon 1 and some polygon 2 + * split, and in that case we move on to the end phase below. + */ + nintersect = 0; + i1m1 = n1 - 1; + i1wrap = -1; + for ( i1 = i1start; i1 < n1; i1++ ) + { + i2m1 = n2 - 1; + i2wrap = -1; + for ( i2 = 0; i2 < n2; i2++ ) + { + if ( !if2[i2] ) + { + /* intersect is acted upon only if a series of conditions are met. */ + ifintersect = !ifnotintersect( + &xintersect[nintersect], &yintersect[nintersect], + x1[i1m1], y1[i1m1], x1[i1], y1[i1], + x2[i2m1], y2[i2m1], x2[i2], y2[i2] ); + ifintersect = ifintersect && !( + xintersect[nintersect] == x1[i1m1] && + yintersect[nintersect] == y1[i1m1] ); + ifintersect = ifintersect && !( + xintersect[nintersect] == x1[i1] && + yintersect[nintersect] == y1[i1] ); + ifintersect = ifintersect && !( + xintersect[nintersect] == x2[i2m1] && + yintersect[nintersect] == y2[i2m1] ); + ifintersect = ifintersect && !( + xintersect[nintersect] == x2[i2] && + yintersect[nintersect] == y2[i2] ); + if ( ifintersect ) + { + /* The above test must be more elaborate if the intersection + * point is a vertex of the first polygon, the second polygon + * or both. ToDo! */ + if ( nintersect == 0 ) + { + i1wraplast = i1wrap; + i2wraplast = i2wrap; + + nintersect++; + } + else + { + /* Have discovered the first two intersections for + * polygon 1 at i1 = i1start or above. */ + /* New i1start is the largest non-negative polygon 1 + * index below the last detected intersect. */ + i1start = MAX( i1wrap, 0 ); + + /* Split polygon 2 at the boundary consisting of + * first intersection, intervening (if any) range1 + * polygon 1 points and second intersection. */ + /* range1 must always be non-negative because i1 + * range only traversed once. */ + range1 = i1wrap - i1wraplast; + /* Polygon 2 intersects could be anywhere (since + * i2 range repeated until get an intersect). + * Divide polygon 2 into two polygons with a + * common boundary consisting of the first intersect, + * range1 points from polygon1 starting at index + * kkstart1 of polygon 1, and the second intersect. */ + kkstart1 = i1wraplast + 1; + + /* Split 1 of polygon2 consists of the + * boundary + range21 points between kkstart21 + * (= i2) and i2wraplast in ascending order of + * polygon 2 indices. N.B. if range21 is zero + * below we change that to n2, i.e., use the + * whole range of polygon 2 in ascending + * order. For this case, range22 (below) will + * be zero and range1 (above) must be nonzero + * (in order to have two intersections). */ + range21 = i2wraplast - i2wrap; + if ( range21 <= 0 ) + range21 += n2; + kkstart21 = i2; + + /* Split 2 of polygon 2 consists of the + * boundary + range22 (= n2 - range21) points + * between kkstart22 (= i2wrap) and i2wraplast + 1 in + * descending order of polygon 2 indices. */ + range22 = n2 - range21; + kkstart22 = i2wrap; + if ( kkstart22 == -1 ) + kkstart22 = i2m1; + nsplit1 = 2 + range1 + range21; + nsplit2 = 2 + range1 + range22; + + if (( xsplit1 = (PLINT *) malloc( nsplit1 * sizeof ( PLINT ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + if (( ysplit1 = (PLINT *) malloc( nsplit1 * sizeof ( PLINT ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + if (( ifsplit1 = (PLINT *) malloc( nsplit1 * sizeof ( PLINT ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + + if (( xsplit2 = (PLINT *) malloc( nsplit2 * sizeof ( PLINT ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + if (( ysplit2 = (PLINT *) malloc( nsplit2 * sizeof ( PLINT ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + if (( ifsplit2 = (PLINT *) malloc( nsplit2 * sizeof ( PLINT ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + /* Common boundary between split1 and split2. */ + k = 0; + xsplit1[k] = xintersect[0]; + ysplit1[k] = yintersect[0]; + ifsplit1[k] = 1; + xsplit2[k] = xintersect[0]; + ysplit2[k] = yintersect[0]; + ifsplit2[k] = 1; + kstart = k + 1; + kk = kkstart1; + /* No wrap checks on kk index below because + * it must always be in valid range (since + * polygon 1 traversed only once). */ + for ( k = kstart; k < range1 + 1; k++ ) + { + xsplit1[k] = x1[kk]; + ysplit1[k] = y1[kk]; + ifsplit1[k] = 2; + xsplit2[k] = x1[kk]; + ysplit2[k] = y1[kk++]; + ifsplit2[k] = 2; + } + xsplit1[k] = xintersect[1]; + ysplit1[k] = yintersect[1]; + ifsplit1[k] = 1; + xsplit2[k] = xintersect[1]; + ysplit2[k] = yintersect[1]; + ifsplit2[k] = 1; + + /* Finish off collecting split1 using ascending kk + * values. */ + kstart = k + 1; + kk = kkstart21; + for ( k = kstart; k < nsplit1; k++ ) + { + xsplit1[k] = x2[kk]; + ysplit1[k] = y2[kk]; + ifsplit1[k] = if2[kk++]; + if ( kk >= n2 ) + kk -= n2; + } + fill_intersection_polygon( recursion_depth + 1, ifclip, fill, + x1, y1, i1start, n1, + xsplit1, ysplit1, ifsplit1, nsplit1 ); + free( xsplit1 ); + free( ysplit1 ); + free( ifsplit1 ); + + /* Finish off collecting split2 using descending kk + * values. */ + kk = kkstart22; + for ( k = kstart; k < nsplit2; k++ ) + { + xsplit2[k] = x2[kk]; + ysplit2[k] = y2[kk]; + ifsplit2[k] = if2[kk--]; + if ( kk < 0 ) + kk += n2; + } + fill_intersection_polygon( recursion_depth + 1, ifclip, fill, + x1, y1, i1start, n1, + xsplit2, ysplit2, ifsplit2, nsplit2 ); + free( xsplit2 ); + free( ysplit2 ); + free( ifsplit2 ); + return; + } + } + } + i2m1 = i2; + i2wrap = i2m1; + } + i1m1 = i1; + i1wrap = i1m1; + } + if ( nintersect != 0 ) + { + plwarn( "fill_intersection_polygon: Internal error; nintersect != 0." ); + return; + } + + /* Look for first vertex in Polygon 2 that does not intersect with 1. */ + for ( i2 = 0; i2 < n2; i2++ ) + { + if ( !if2[i2] ) + break; + } + + if ( i2 < n2 && pointinpolygon( n1, x1, y1, x2[i2], y2[i2] )) + { + /* All of polygon 2 inside polygon 1. */ + nfill = n2; + xfiller = x2; + yfiller = y2; + } + else + { + /* Look for first vertex in polygon 1 that is inside polygon 2. */ + for ( i1 = 0; i1 < n1; i1++ ) + { + if ( pointinpolygon( n2, x2, y2, x1[i1], y1[i1] )) + break; + } + + if ( i1 < n1 ) + { + /* All of polygon 1 inside polygon 2 */ + nfill = n1; + xfiller = x1; + yfiller = y1; + } + else + plwarn( "fill_intersection_polygon: inscribed polygon not yet implemented" ); + } + if ( nfill > 0 ) + { + if (( xfill = (short *) malloc( nfill * sizeof ( short ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + if (( yfill = (short *) malloc( nfill * sizeof ( short ))) == NULL ) + { + plexit( "fill_intersection_polygon: Insufficient memory" ); + } + for ( ifill = 0; ifill < nfill; ifill++ ) + { + xfill[ifill] = xfiller[ifill]; + yfill[ifill] = yfiller[ifill]; + } + ( *fill )( xfill, yfill, nfill ); + free( xfill ); + free( yfill ); + } + + return; +} + +/* Find if an intersection (N.B. including end points) exists between + * straight line segments A and B defined by their endpoints xA1, yA1, + * xA2, yA2, xB1, yB1, xB2, yB2. If not return true (-1 if parallel, + * 1 if intersecting away from segments). If true, return false. + * Except for the parallel line case always return the intersection, + * (xintersect, yintersect) via the argument list. */ + +int +ifnotintersect( PLINT * xintersect, PLINT * yintersect, + PLINT xA1, PLINT yA1, PLINT xA2, PLINT yA2, + PLINT xB1, PLINT yB1, PLINT xB2, PLINT yB2 ) +{ + PLINT xA2A1, yA2A1, xB2B1, yB2B1; + PLINT xB1A1, yB1A1, xB2A1, yB2A1; + PLFLT factor; + /* + * Two linear equations to be solved for x and y. + * y = ((x - xA1)*yA2 + (xA2 - x)*yA1)/(xA2 - xA1) + * y = ((x - xB1)*yB2 + (xB2 - x)*yB1)/(xB2 - xB1) + * + * Transform those two equations to coordinate system with origin + * at (xA1, yA1). + * y' = x'*yA2A1/xA2A1 + * y' = ((x' - xB1A1)*yB2A1 + (xB2A1 - x')*yB1A1)/xB2B1 + * ==> + * x' = -( + * (-xB1A1*yB2A1 + xB2A1*yB1A1)/xB2B1)/ + * (yB2B1/xB2B1 - yA2A1/xA2A1) + * = (xB1A1*yB2A1 - xB2A1*yB1A1)*xA2A1/ + * (xA2A1*yB2B1 - yA2A1*xB2B1) + * + */ + + xA2A1 = xA2 - xA1; + yA2A1 = yA2 - yA1; + xB2B1 = xB2 - xB1; + yB2B1 = yB2 - yB1; + + factor = xA2A1 * yB2B1 - yA2A1 * xB2B1; + /* If two line segments are parallel (including identical) .... */ + if ( fabs( factor ) == 0. ) + return -1; + xB1A1 = xB1 - xA1; + yB1A1 = yB1 - yA1; + xB2A1 = xB2 - xA1; + yB2A1 = yB2 - yA1; + + factor = ( xB1A1 * yB2A1 - yB1A1 * xB2A1 ) / factor; + *xintersect = factor * xA2A1 + xA1; + *yintersect = factor * yA2A1 + yA1; + /* The x and y range checks (which include end points) are redundant + * with each other for infinite-precision floating-point arithmetic. + * But we don't have that so do these "redundant" checks. */ + if ( BETW( *xintersect, xA1, xA2 ) && BETW( *yintersect, yA1, yA2 ) && + BETW( *xintersect, xB1, xB2 ) && BETW( *yintersect, yB1, yB2 )) + return 0; + else + return 1; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |