Function:s2skypa
From S2PLOT
(Difference between revisions)
Revision as of 04:45, 22 November 2007
s2skypa
Draw a skyscraper plot with/without walls.
Prototype
void s2skypa(float **data, int nx, int ny,int i1, int i2, int j1, int j2,float datamin, float datamax,
float *tr, int walls, int idx_left, int idx_front);
Description
Draw a skyscraper plot with arbitrary rotation / skew / translation specified by the tr matrix. If walls = 1, then draw the building walls.
See Also
s2scir | Set the range of colour indices used for shading. |
s2surp | Draw a colour surface representation of the 2-dimensional array, data, containing nx * ny values. |
s2impa | Draw an impulse plot with/without trunks |
PGPLOT Equivalent
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "s2plot.h"
#define XLIMIT 10.0
#define YLIMIT 10.0
#define ZLIMIT 10.0
#define TWOPI 6.2831853
#define NX 32
#define NY 32
int main(int argc, char *argv[])
{
float x1 = -XLIMIT, x2 = XLIMIT; /* x world coord range */
float y1 = -YLIMIT, y2 = YLIMIT; /* y world coord range */
float z1 = -ZLIMIT, z2 = ZLIMIT; /* z world coord range */
int i, j; /* Loop variables */
float **image; /* 2D array for image */
float minz = 9e30; /* Minimum value */
float maxz = -9e30; /* Maximum value */
float x, y, dx, dy; /* Temporary variables */
float tr[12]; /* Transformation matrix */
int walls = 1; /* Should walls be drawn? */
int lcolor = S2_PG_LTGREY; /* Colour index for left-hand wall
*/
int fcolor = S2_PG_DKGREY; /* Automatic colour */
s2opend("/?",argc,argv); /* Open the display */
dx = (x2-x1)/(float)(NX-1); /* Spacing in X */
dy = (y2-y1)/(float)(NY-1); /* Spacing in Y */
s2swin(x1-0.5*dx,x2+0.5*dx,y1-0.5*dy,y2+0.5*dy,z1,z2);
/* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
dx = (x2-x1)/(float)(NX-1); /* Spacing in X */
dy = (y2-y1)/(float)(NY-1); /* Spacing in Y */
image = (float **)calloc(NX, sizeof(float **)); /* Allocate memory */
for (i=0;i<NX;i++) {
image[i] = (float *)calloc(NY, sizeof(float *)); /* Allocate memory */
x = i*dx + x1;
for (j=0;j<NY;j++) {
y = j*dy + y1;
image[i][j] = -sqrt(x*x + y*y); /* Data points */
image[i][j] += rand() / (float)RAND_MAX;
minz = (image[i][j] < minz) ? image[i][j] : minz;
maxz = (image[i][j] > maxz) ? image[i][j] : maxz;
}
}
s2icm("rainbow", 1000, 1500); /* Install colour map */
s2scir(1000, 1500); /* Set colour range */
/* Set up the transformation mapping from grid to world coordinatee */
tr[0] = x1; tr[1] = (x2-x1)/(float)(NX-1); tr[2] = 0.0; tr[3] = 0.0;
tr[4] = y1; tr[5] = 0.0; tr[6] = (y2-y1)/(float)(NY-1); tr[7] = 0.0;
tr[8] = z1; tr[9] = 0.0; tr[10] = 0.0; tr[11] = 0.0;
/* Draw the data mapped to the z-plane */
s2surpa(image, NX, NY, 0, NX-1, 0, NY-1, minz, maxz, tr);
tr[8] = z1 - minz * (z2 - z1) / (maxz - minz); /* Fix up z minimum */
tr[11] = (z2 - z1) / (maxz - minz); /* Fix up z range */
/* with automatic colored building walls: */
s2skypa(image, NX, NY, 0, (NX-1)/2, 0, NY-1, minz, maxz, tr, walls, -1, -1);
/* with grey walls: idx_left and idx_right specified */
s2skypa(image, NX, NY, (NX-1)/2+1, NX-1, 0, NY-1, minz, maxz, tr, walls,
lcolor, fcolor);
s2show(1); /* Show the S2PLOT window */
return 1;
}
Back to S2PLOT function list.