Function:ns2qsq

From S2PLOT

Jump to: navigation, search

ns2qsq

Query general surface quality.

Prototype

int ns2qsq(void);

Description

Query general surface quality high (1) or low (0, default). The former calculates weighted normals for all vertices, while the latter calculates a single normal per facet of the surface. The former should be used for export to VRML.

See Also

ns2ssqSet the general surface quality.
ns2cisCreate an isosurface object.
ns2ciscCreate an isosurface object with a colour function.
ns2dis Draw an isosurface object
ns2sisl Change the level of isosurface
ns2siscSet the colour for an isosurface.

Code Example

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

#define CELLS 30

int id1;                                /* Global variable: isosurface id */

void cb(double *t, int *kc)
{
   char string[255];
   int isq = ns2qsq();                  /* Query the surface quality */
   sprintf(string,"Surface quality is: %d. Press <space> to toggle",isq);
   s2lab("","","",string);              /* Show a label on screen */
   ns2ssq(*kc%2);                       /* Set the surface quality */
   ns2dis(id1, 1);                      /* Display an 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 = 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.);

   cs2scb(cb);                          /* Install dynamic callback */

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

   return 1;
}

Back to S2PLOT function list.


Personal tools