The R Project SVN R

Rev

Rev 45049 | Rev 45667 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45049 Rev 45446
Line 1190... Line 1190...
1190
			}
1190
			}
1191
		    } /* switch (method) */
1191
		    } /* switch (method) */
1192
 
1192
 
1193
		    if (method == 0) {
1193
		    if (method == 0) {
1194
			GPolyline(ns, xxx, yyy, USER, dd);
1194
			GPolyline(ns, xxx, yyy, USER, dd);
1195
			GText(xxx[indx], yyy[indx], USER, buffer, 
1195
			GText(xxx[indx], yyy[indx], USER, buffer,
1196
			      CE_NATIVE/*FIX*/,
1196
			      CE_NATIVE/*FIX*/,
1197
			      .5, .5, 0, dd);
1197
			      .5, .5, 0, dd);
1198
		    }
1198
		    }
1199
		    else {
1199
		    else {
1200
			for (iii = 0; iii < indx; iii++)
1200
			for (iii = 0; iii < indx; iii++)
Line 1306... Line 1306...
1306
				   angle to draw text
1306
				   angle to draw text
1307
				*/
1307
				*/
1308
				GConvert(&ux, &uy, USER, INCHES, dd);
1308
				GConvert(&ux, &uy, USER, INCHES, dd);
1309
				GConvert(&vx, &vy, USER, INCHES, dd);
1309
				GConvert(&vx, &vy, USER, INCHES, dd);
1310
				/* 0, .5 => left, centre justified */
1310
				/* 0, .5 => left, centre justified */
1311
				GText (ux, uy, INCHES, buffer, 
1311
				GText (ux, uy, INCHES, buffer,
1312
				       CE_NATIVE/*FIX*/,0, .5,
1312
				       CE_NATIVE/*FIX*/,0, .5,
1313
				       (180 / 3.14) * atan2(vy - uy, vx - ux),
1313
				       (180 / 3.14) * atan2(vy - uy, vx - ux),
1314
				       dd);
1314
				       dd);
1315
			    }
1315
			    }
1316
			} /* if (gotLabel) */
1316
			} /* if (gotLabel) */
Line 1459... Line 1459...
1459
    if (zmin >= zmax) {
1459
    if (zmin >= zmax) {
1460
	if (zmin == zmax)
1460
	if (zmin == zmax)
1461
	    warning(_("all z values are equal"));
1461
	    warning(_("all z values are equal"));
1462
	else
1462
	else
1463
	    warning(_("all z values are NA"));
1463
	    warning(_("all z values are NA"));
1464
        UNPROTECT(4);
1464
	UNPROTECT(4);
1465
	return R_NilValue;
1465
	return R_NilValue;
1466
    }
1466
    }
1467
 
1467
 
1468
    /* change to 1e-3, reconsidered because of PR#897
1468
    /* change to 1e-3, reconsidered because of PR#897
1469
     * but 1e-7, and even  2*DBL_EPSILON do not prevent inf.loop in contour().
1469
     * but 1e-7, and even  2*DBL_EPSILON do not prevent inf.loop in contour().
Line 1731... Line 1731...
1731
				    z[i - 1 + (j - 1) * nx],
1731
				    z[i - 1 + (j - 1) * nx],
1732
				    z[i + (j - 1) * nx],
1732
				    z[i + (j - 1) * nx],
1733
				    z[i - 1 + j * nx],
1733
				    z[i - 1 + j * nx],
1734
				    z[i + j * nx],
1734
				    z[i + j * nx],
1735
				    px, py, pz, &npt);
1735
				    px, py, pz, &npt);
1736
                if (npt > 2)
1736
		if (npt > 2)
1737
		    GPolygon(npt, px, py, USER, col[(k-1)%ncol],
1737
		    GPolygon(npt, px, py, USER, col[(k-1)%ncol],
1738
			     R_TRANWHITE, dd);
1738
			     R_TRANWHITE, dd);
1739
	    }
1739
	    }
1740
	}
1740
	}
1741
    }
1741
    }
Line 1900... Line 1900...
1900
}
1900
}
1901
 
1901
 
1902
 
1902
 
1903
static void DrawFacets(double *z, double *x, double *y, int nx, int ny,
1903
static void DrawFacets(double *z, double *x, double *y, int nx, int ny,
1904
		       int *indx, double xs, double ys, double zs,
1904
		       int *indx, double xs, double ys, double zs,
1905
	               int *col, int ncol, int border)
1905
		       int *col, int ncol, int border)
1906
{
1906
{
1907
    double xx[4], yy[4], shade = 0;
1907
    double xx[4], yy[4], shade = 0;
1908
    Vector3d u, v;
1908
    Vector3d u, v;
1909
    int i, j, k, n, nx1, ny1, icol, nv;
1909
    int i, j, k, n, nx1, ny1, icol, nv;
1910
    unsigned int newcol, r, g, b;
1910
    unsigned int newcol, r, g, b;
Line 1917... Line 1917...
1917
	nv = 0;
1917
	nv = 0;
1918
	i = indx[k] % nx1;
1918
	i = indx[k] % nx1;
1919
	j = indx[k] / nx1;
1919
	j = indx[k] / nx1;
1920
	icol = (i + j * nx1) % ncol;
1920
	icol = (i + j * nx1) % ncol;
1921
	if (DoLighting) {
1921
	if (DoLighting) {
1922
            /* Note we must scale here */
1922
	    /* Note we must scale here */
1923
	    u[0] = xs * (x[i+1] - x[i]);
1923
	    u[0] = xs * (x[i+1] - x[i]);
1924
	    u[1] = ys * (y[j] - y[j+1]);
1924
	    u[1] = ys * (y[j] - y[j+1]);
1925
	    u[2] = zs * (z[(i+1)+j*nx] - z[i+(j+1)*nx]);
1925
	    u[2] = zs * (z[(i+1)+j*nx] - z[i+(j+1)*nx]);
1926
	    v[0] = xs * (x[i+1] - x[i]);
1926
	    v[0] = xs * (x[i+1] - x[i]);
1927
	    v[1] = ys * (y[j+1] - y[j]);
1927
	    v[1] = ys * (y[j+1] - y[j]);
Line 2096... Line 2096...
2096
    if (front)
2096
    if (front)
2097
	gpptr(dd)->lty = LTY_DOTTED;
2097
	gpptr(dd)->lty = LTY_DOTTED;
2098
    else
2098
    else
2099
	gpptr(dd)->lty = LTY_SOLID;
2099
	gpptr(dd)->lty = LTY_SOLID;
2100
    for (f = 0; f < 6; f++) {
2100
    for (f = 0; f < 6; f++) {
2101
        p0 = Face[f][0];
2101
	p0 = Face[f][0];
2102
        p1 = Face[f][1];
2102
	p1 = Face[f][1];
2103
        p2 = Face[f][2];
2103
	p2 = Face[f][2];
2104
        p3 = Face[f][3];
2104
	p3 = Face[f][3];
2105
 
2105
 
2106
	u0[0] = x[Vertex[p0][0]];
2106
	u0[0] = x[Vertex[p0][0]];
2107
	u0[1] = y[Vertex[p0][1]];
2107
	u0[1] = y[Vertex[p0][1]];
2108
	u0[2] = z[Vertex[p0][2]];
2108
	u0[2] = z[Vertex[p0][2]];
2109
	u0[3] = 1;
2109
	u0[3] = 1;
Line 2127... Line 2127...
2127
 
2127
 
2128
	/* Visibility test. */
2128
	/* Visibility test. */
2129
	/* Determine whether the surface normal is toward the eye. */
2129
	/* Determine whether the surface normal is toward the eye. */
2130
	/* Note that we only draw lines once. */
2130
	/* Note that we only draw lines once. */
2131
 
2131
 
2132
        for (i = 0; i < 3; i++) {
2132
	for (i = 0; i < 3; i++) {
2133
	    d[i] = v1[i]/v1[3] - v0[i]/v0[3];
2133
	    d[i] = v1[i]/v1[3] - v0[i]/v0[3];
2134
	    e[i] = v2[i]/v2[3] - v1[i]/v1[3];
2134
	    e[i] = v2[i]/v2[3] - v1[i]/v1[3];
2135
        }
2135
	}
2136
	nearby = (d[0]*e[1] - d[1]*e[0]) < 0;
2136
	nearby = (d[0]*e[1] - d[1]*e[0]) < 0;
2137
 
2137
 
2138
	if ((front && nearby) || (!front && !nearby)) {
2138
	if ((front && nearby) || (!front && !nearby)) {
2139
	    if (!EdgeDone[Edge[f][0]]++)
2139
	    if (!EdgeDone[Edge[f][0]]++)
2140
		GLine(v0[0]/v0[3], v0[1]/v0[3],
2140
		GLine(v0[0]/v0[3], v0[1]/v0[3],
Line 2193... Line 2193...
2193
    return angle;
2193
    return angle;
2194
}
2194
}
2195
 
2195
 
2196
static void PerspAxis(double *x, double *y, double *z,
2196
static void PerspAxis(double *x, double *y, double *z,
2197
		      int axis, int axisType, int nTicks, int tickType,
2197
		      int axis, int axisType, int nTicks, int tickType,
2198
		      const char *label, cetype_t enc, pGEDevDesc dd) 
2198
		      const char *label, cetype_t enc, pGEDevDesc dd)
2199
{
2199
{
2200
    Vector3d u1, u2, u3, v1, v2, v3;
2200
    Vector3d u1, u2, u3, v1, v2, v3;
2201
    double tickLength = .03; /* proportion of axis length */
2201
    double tickLength = .03; /* proportion of axis length */
2202
    double min, max, d_frac;
2202
    double min, max, d_frac;
2203
    double *range = NULL; /* -Wall */
2203
    double *range = NULL; /* -Wall */
Line 2357... Line 2357...
2357
	    /* Draw tick line */
2357
	    /* Draw tick line */
2358
	    GLine(v1[0]/v1[3], v1[1]/v1[3],
2358
	    GLine(v1[0]/v1[3], v1[1]/v1[3],
2359
		  v2[0]/v2[3], v2[1]/v2[3], USER, dd);
2359
		  v2[0]/v2[3], v2[1]/v2[3], USER, dd);
2360
	    /* Draw tick label */
2360
	    /* Draw tick label */
2361
	    GText(v3[0]/v3[3], v3[1]/v3[3], USER,
2361
	    GText(v3[0]/v3[3], v3[1]/v3[3], USER,
2362
		  CHAR(STRING_ELT(lab, i)), 
2362
		  CHAR(STRING_ELT(lab, i)),
2363
		  getCharCE(STRING_ELT(lab, i)),
2363
		  getCharCE(STRING_ELT(lab, i)),
2364
		  .5, .5, 0, dd);
2364
		  .5, .5, 0, dd);
2365
	}
2365
	}
2366
	UNPROTECT(2);
2366
	UNPROTECT(2);
2367
	break;
2367
	break;
Line 2377... Line 2377...
2377
 * The strategy is to determine which corner has the lowest y-value
2377
 * The strategy is to determine which corner has the lowest y-value
2378
 * to decide which of the x- and y-axes to label AND which corner
2378
 * to decide which of the x- and y-axes to label AND which corner
2379
 * has the lowest x-value to decide which of the z-axes to label
2379
 * has the lowest x-value to decide which of the z-axes to label
2380
 */
2380
 */
2381
static void PerspAxes(double *x, double *y, double *z,
2381
static void PerspAxes(double *x, double *y, double *z,
2382
                      const char *xlab, cetype_t xenc,
2382
		      const char *xlab, cetype_t xenc,
2383
		      const char *ylab, cetype_t yenc, 
2383
		      const char *ylab, cetype_t yenc,
2384
		      const char *zlab, cetype_t zenc,
2384
		      const char *zlab, cetype_t zenc,
2385
		      int nTicks, int tickType, pGEDevDesc dd)
2385
		      int nTicks, int tickType, pGEDevDesc dd)
2386
{
2386
{
2387
    int xAxis=0, yAxis=0, zAxis=0; /* -Wall */
2387
    int xAxis=0, yAxis=0, zAxis=0; /* -Wall */
2388
    int xpdsave;
2388
    int xpdsave;
Line 2556... Line 2556...
2556
    PROTECT(col = FixupCol(col, gpptr(dd)->bg));
2556
    PROTECT(col = FixupCol(col, gpptr(dd)->bg));
2557
    ncol = LENGTH(col);
2557
    ncol = LENGTH(col);
2558
    if (ncol < 1) error(_("invalid '%s' specification"), "col");
2558
    if (ncol < 1) error(_("invalid '%s' specification"), "col");
2559
    if(!R_OPAQUE(INTEGER(col)[0])) DoLighting = FALSE;
2559
    if(!R_OPAQUE(INTEGER(col)[0])) DoLighting = FALSE;
2560
    PROTECT(border = FixupCol(border, gpptr(dd)->fg));
2560
    PROTECT(border = FixupCol(border, gpptr(dd)->fg));
2561
    if (length(border) < 1) 
2561
    if (length(border) < 1)
2562
	error(_("invalid '%s' specification"), "border");
2562
	error(_("invalid '%s' specification"), "border");
2563
 
2563
 
2564
    GSetState(1, dd);
2564
    GSetState(1, dd);
2565
    GSavePars(dd);
2565
    GSavePars(dd);
2566
    ProcessInlinePars(args, dd, call);
2566
    ProcessInlinePars(args, dd, call);
Line 2568... Line 2568...
2568
	gpptr(dd)->fg = INTEGER(border)[0];
2568
	gpptr(dd)->fg = INTEGER(border)[0];
2569
    gpptr(dd)->xlog = gpptr(dd)->ylog = FALSE;
2569
    gpptr(dd)->xlog = gpptr(dd)->ylog = FALSE;
2570
 
2570
 
2571
    /* Set up the light vector (if any) */
2571
    /* Set up the light vector (if any) */
2572
    if (DoLighting)
2572
    if (DoLighting)
2573
        SetUpLight(ltheta, lphi);
2573
	SetUpLight(ltheta, lphi);
2574
 
2574
 
2575
    /* Mark box edges as undrawn */
2575
    /* Mark box edges as undrawn */
2576
    for (i = 0; i< 12; i++)
2576
    for (i = 0; i< 12; i++)
2577
	EdgeDone[i] = 0;
2577
	EdgeDone[i] = 0;
2578
 
2578
 
Line 2606... Line 2606...
2606
     * This is the "painters" algorithm. */
2606
     * This is the "painters" algorithm. */
2607
 
2607
 
2608
    GMode(1, dd);
2608
    GMode(1, dd);
2609
 
2609
 
2610
    if (dobox) {
2610
    if (dobox) {
2611
        PerspBox(0, REAL(xlim), REAL(ylim), REAL(zlim), dd);
2611
	PerspBox(0, REAL(xlim), REAL(ylim), REAL(zlim), dd);
2612
	if (doaxes) {
2612
	if (doaxes) {
2613
	    SEXP xl = STRING_ELT(xlab, 0), yl = STRING_ELT(ylab, 0),
2613
	    SEXP xl = STRING_ELT(xlab, 0), yl = STRING_ELT(ylab, 0),
2614
		zl = STRING_ELT(zlab, 0);
2614
		zl = STRING_ELT(zlab, 0);
2615
	    PerspAxes(REAL(xlim), REAL(ylim), REAL(zlim),
2615
	    PerspAxes(REAL(xlim), REAL(ylim), REAL(zlim),
2616
		      (xl == NA_STRING)? "" : CHAR(xl), getCharCE(xl),
2616
		      (xl == NA_STRING)? "" : CHAR(xl), getCharCE(xl),
Line 2623... Line 2623...
2623
    DrawFacets(REAL(z), REAL(x), REAL(y), nrows(z), ncols(z), INTEGER(indx),
2623
    DrawFacets(REAL(z), REAL(x), REAL(y), nrows(z), ncols(z), INTEGER(indx),
2624
	       1/xs, 1/ys, expand/zs,
2624
	       1/xs, 1/ys, expand/zs,
2625
	       INTEGER(col), ncol, INTEGER(border)[0]);
2625
	       INTEGER(col), ncol, INTEGER(border)[0]);
2626
 
2626
 
2627
    if (dobox)
2627
    if (dobox)
2628
        PerspBox(1, REAL(xlim), REAL(ylim), REAL(zlim), dd);
2628
	PerspBox(1, REAL(xlim), REAL(ylim), REAL(zlim), dd);
2629
    GMode(0, dd);
2629
    GMode(0, dd);
2630
 
2630
 
2631
    GRestorePars(dd);
2631
    GRestorePars(dd);
2632
    UNPROTECT(10);
2632
    UNPROTECT(10);
2633
    if (GRecording(call, dd))
2633
    if (GRecording(call, dd))
2634
        GErecordGraphicOperation(op, originalArgs, dd);
2634
	GErecordGraphicOperation(op, originalArgs, dd);
2635
 
2635
 
2636
    PROTECT(x = allocVector(REALSXP, 16));
2636
    PROTECT(x = allocVector(REALSXP, 16));
2637
    PROTECT(y = allocVector(INTSXP, 2));
2637
    PROTECT(y = allocVector(INTSXP, 2));
2638
    for (i = 0; i < 4; i++)
2638
    for (i = 0; i < 4; i++)
2639
	for (j = 0; j < 4; j++)
2639
	for (j = 0; j < 4; j++)
Line 2642... Line 2642...
2642
    INTEGER(y)[1] = 4;
2642
    INTEGER(y)[1] = 4;
2643
    setAttrib(x, R_DimSymbol, y);
2643
    setAttrib(x, R_DimSymbol, y);
2644
    UNPROTECT(2);
2644
    UNPROTECT(2);
2645
    return x;
2645
    return x;
2646
}
2646
}
2647
 
-