Function:ns2sisc
From S2PLOT
(Difference between revisions)
Revision as of 23:24, 3 December 2007 S2plot admin (Talk | contribs) ← Previous diff |
Revision as of 23:25, 3 December 2007 S2plot admin (Talk | contribs) Next diff → |
||
Line 9: | Line 9: | ||
==Description== | ==Description== | ||
- | Set the RGB colour for an isosurface. | + | Set the (r,g,b) colour for an isosurface. To view changes, you must call ns2dis with the force argument set to 1. |
== See Also == | == See Also == | ||
Line 18: | Line 18: | ||
<tr><td>[[Function:ns2sisl | ns2sisl ]]</td><td>Change the level of isosurface </td></tr> | <tr><td>[[Function:ns2sisl | ns2sisl ]]</td><td>Change the level of isosurface </td></tr> | ||
<tr><td>[[Function:ns2sisa | ns2sisa]]</td><td>Set the alpha channel for an isosurface. </td></tr> | <tr><td>[[Function:ns2sisa | ns2sisa]]</td><td>Set the alpha channel for an isosurface. </td></tr> | ||
+ | <tr><td>[[Function:struct_COLOUR | struct COLOUR]]</td><td>Data structure for (r,g,b) colour indices. </td></tr> | ||
</table> | </table> | ||
Revision as of 23:25, 3 December 2007
ns2sisc
Set the isosurface colour.
Prototype
void ns2sisc(int isid, float r, float g, float b);
Description
Set the (r,g,b) colour for an isosurface. 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 |
ns2sisa | Set the alpha channel for an isosurface. |
struct COLOUR | Data structure for (r,g,b) colour indices. |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "s2plot.h"
/* Global variables */
int id1, id2; /* IDs for isosurface object */
void cb(double *t, int *kc){
static int count = 0; /* Counter for refreshing */
int force = 1; /* Force redraw of surface */
float r, g, b; /* Isosurface colour */
if (count == 12) { /* About once per half second */
count = 0; /* Reset counter */
r = drand48(); /* Random colours */
g = drand48();
b = drand48();
ns2sisc(id1, r, g, b); /* Set isosurface colour */
} else {
count++; /* Keep counting */
}
ns2dis(id1, force); /* Draw first isosurface */
ns2dis(id2, force); /* Draw second 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 */
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 = 1.0; /* Set the alpha channel */
trans = 't'; /* Opaque isosurface */
/* Create the first isosurface object */
id1 = ns2cis(grid, nx, ny, nz, 0, nx-1, 0, ny-1, 0, nz-1,
tr, level, resolution, trans, alpha, 1., 1., 0.);
level = 0.8; /* Set the isosurface level */
/* Create the second isosurface object */
id2 = 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.