Function:ns2sisa
From S2PLOT
(Difference between revisions)
Revision as of 22:10, 3 December 2007 S2plot admin (Talk | contribs) ← Previous diff |
Current revision S2plot admin (Talk | contribs) |
||
Line 24: | Line 24: | ||
#include <stdio.h> | #include <stdio.h> | ||
#include <stdlib.h> | #include <stdlib.h> | ||
+ | #include <time.h> | ||
#include <math.h> | #include <math.h> | ||
#include "s2plot.h" | #include "s2plot.h" | ||
Line 63: | Line 64: | ||
float alpha; /* Alpha channel */ | float alpha; /* Alpha channel */ | ||
char trans; /* Drawing mode for isosurface */ | char trans; /* Drawing mode for isosurface */ | ||
+ | |||
+ | srand48((long)time(NULL)); /* Seed random numbers */ | ||
nx = 30; /* Grid dimensions */ | nx = 30; /* Grid dimensions */ | ||
Line 91: | Line 94: | ||
} | } | ||
} | } | ||
+ | |||
level = 0.2; /* Set the isosurface level */ | level = 0.2; /* Set the isosurface level */ | ||
resolution = 1; /* Set the isosurface resolution */ | resolution = 1; /* Set the isosurface resolution */ | ||
Line 105: | Line 109: | ||
return 1; | return 1; | ||
} | } | ||
+ | |||
</pre></code> | </pre></code> |
Current revision
ns2sisa
Set the alpha channel for an isosurface.
Prototype
void ns2sisa(int isid, float alpha, char trans);
Description
Set the isosurface alpha channel and transparency. To view changes, you must call ns2dis with the force argument set to 1.
See Also
ns2cis | Create an isosurface object. |
ns2cisc | Create an isosurface object with a colour function. |
ns2dis | Draw an isosurface object |
ns2sisl | Change the level of isosurface |
ns2sisc | Set the colour for an isosurface. |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "s2plot.h"
/* Global variabl */
int id; /* ID for isosurface object */
void cb(double *t, int *kc)
{
static int count = 0; /* Count number of times in */
static float alpha = 0.0; /* Isosurface alpha channel */
int force = 1; /* Force redraw of surface */
float dummy; /* A random number */
char trans; /* Isosurface transparency */
if (count == 12) { /* About once per half second */
count = 0; /* Reset counter */
alpha = drand48(); /* Random alpha channel value */
dummy = drand48(); /* Random number */
if (dummy > 0.6) trans = 't'; /* Select transparency type */
else if (dummy > 0.3) trans = 's';
else trans = 'o';
ns2sisa(id, alpha, trans); /* Set the new isosurface values */
} else {
count++; /* Keep counting */
}
ns2dis(id, force); /* Draw the isosurface */
}
int main(int argc, char *argv[])
{
int i, j, k; /* Loop variables */
float x, y, z; /* Dummy variables for grid values */
int nx, ny, nz; /* Number of cells in grid */
float ***grid; /* Grid data */
float tr[12]; /* Transformation matrix */
int resolution; /* Resolution of isosurface */
float level; /* Isosurface level to plot */
float alpha; /* Alpha channel */
char trans; /* Drawing mode for isosurface */
srand48((long)time(NULL)); /* Seed random numbers */
nx = 30; /* Grid dimensions */
ny = 30;
nz = 30;
/* Create transpose matrix mapping data indices to world coords */
tr[0] = tr[4] = tr[8] = 0.0; /* Offsets */
tr[1] = tr[6] = tr[11] = 1.0; /* Increments */
tr[2] = tr[3] = tr[5] = tr[7] = tr[9] = tr[10] = 0.; /* Cross terms */
s2opend("/?",argc, argv); /* Open the display */
s2swin(0, nx-1, 0, ny-1, 0, nz-1); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
/* allocate and generate the data grid */
grid = (float ***)malloc(nx * sizeof(float **));
for (i = 0; i < nx; i++) {
grid[i] = (float **)malloc(ny * sizeof(float *));
x = (float)(i) / (float)(nx - 1);
for (j = 0; j < ny; j++) {
grid[i][j] = (float *)malloc(nz * sizeof(float));
y = (float)(j) / (float)(ny - 1);
for (k = 0; k < nz; k++) {
z = (float)(k) / (float)(nz - 1);
grid[i][j][k] = x*x*x + y*y - z*z*z*z;
}
}
}
level = 0.2; /* Set the isosurface level */
resolution = 1; /* Set the isosurface resolution */
alpha = 0.0; /* Set the alpha channel */
trans = 'o'; /* Opaque isosurface */
/* Create the isosurface object */
id = ns2cis(grid, nx, ny, nz, 0, nx-1, 0, ny-1, 0, nz-1,
tr, level, resolution, trans, alpha, 1., 1., 0.);
s2scb(&cb); /* Install a dynamic callback */
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.