Function:ns2cis

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 01:10, 30 October 2007
S2plot admin (Talk | contribs)

← Previous diff
Revision as of 01:11, 30 October 2007
S2plot admin (Talk | contribs)

Next diff →
Line 6: Line 6:
<code><pre> <code><pre>
-int ns2cis(float ***grid, int adim, int bdim, int cdim, int a1, int a2, int b1, int b2, int c1, int c2, float *tr, float level, int resolution, char trans, float alpha, float red, float green, float blue);+int ns2cis(float ***grid, int adim, int bdim, int cdim, int a1, int a2, int b1, int b2, int c1, int c2,
 +float *tr, float level, int resolution, char trans, float alpha, float red, float green, float blue);
</pre></code> </pre></code>

Revision as of 01:11, 30 October 2007

ns2cis

Create an isosurface object

Prototype

int ns2cis(float ***grid, int adim, int bdim, int cdim, int a1, int a2, int b1, int b2, int c1, int c2, 
float *tr, float level, int resolution, char trans, float alpha, float red, float green, float blue);

Description

Draw an isosurface of a data volume, at given level. The data in grid is a three-dimensional volume indexed by: grid[0..(adim-1)][0..(bdim-1)][0..(cdim-1)].

The slice of data actually plotted is indexed by [a1..a2][b1..b2][c1..c2] (as for s2vect3, for example).

tr is the transformation matrix which maps indices into the grid onto the x, y and z axes of the 3d world space. The standard (non-rotated, non-skewed) transformation would have tr[2], tr[3], tr[5], tr[7], tr[9] and tr[10] all zero.

The transformation matrix is:

  • x = tr[0] + tr[1] * ia + tr[2] * ib + tr[3] * ic
  • y = tr[4] + tr[5] * ia + tr[6] * ib + tr[7] * ic
  • z = tr[8] + tr[9] * ia + tr[10]* ib + tr[11]* ic

Provide tr = NULL to use the default, unit transformation.

level gives the level at which the isosurface should be drawn. Skip every nth cell as given by resolution. If n = 1 then no skipping occurs.

Transparency of the surface is controlled by the alpha-channel parameter, alpha, between 0 and 1, and trans:

  • trans = 'o' for opaque;
  • trans = 't' for "piling up"; and
  • trans = 's' for transparency that can occlude.

The RGB colour of the isosurface is provided by red, green and blue in the range [0,1].

See Also

ns2cisc Create an isosurface object with a colour function
ns2dis Draw an isosurface object
ns2sisl Change the level of isosurface
s2vect3 Draw a vector map of a 3D data array, with blanking.
struct_COLOUR Data structure for (r,g,b) colour indices.


Code Example

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "s2plot.h"

#define CELLS 30

void colorfn(float *x, float *y, float *z, float *r, float *g, float *b) 
/* Isosurface colouring function */
{
   *r = 0.2 + 0.5 * (*x) / (float)(CELLS - 1);
   *g = 0.0 + 0.8 * (*y) / (float)(CELLS - 1);
   *b = 0.6 + 0.2 * (*z) / (float)(CELLS - 1);
}

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 */
   int id1, id2;			/* ID for isosurface objects */

   nx = CELLS; 				/* Grid dimensions */
   ny = CELLS;
   nz = CELLS;

  /* 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.9;			/* Set the alpha channel */
   trans      = 'o';			/* Opaque isosurface */

/* Create the 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.);
   ns2dis(id1, 0);			/* Draw it */

   level      = 0.7;			/* Set the isosurface level */
   resolution = 6;			/* Set the isosurface resolution */
   alpha      = 0.5;			/* Set the alpha channel */
   trans      = 's';			/* Opaque isosurface */

/* Create the isosurface object */
   id2 = ns2cisc(grid, nx, ny, nz, 0, nx-1, 0, ny-1, 0, nz-1,
		    tr, level, resolution, trans, alpha, colorfn);
   ns2dis(id2, 0);			/* Draw it */

   s2show(1);				/* Open the s2plot window */

   return 1;
}

Back to S2PLOT function list.


Personal tools