Function:s2chromacpts

From S2PLOT

Jump to: navigation, search

s2chromacpts

Plot cartesian points using chromastereoscopic colouring for depth

Prototype

void s2chromacpts(int n, float *ix, float *iy, float *iz, float *dist, float *size, float dmin, float dmax);

Description

Plot points on a Cartesian grid at given locations (ix,iy,iz), coloured by the current colormap. Array dist gives the distance to each point from the camera. Index into map is calculated linearly between dmin and dmax. This function is so called because with the right colormap, a chromastereoscopic view will be produced. Array size contains the desired sizes of the points.

See Also

s2chromapts Plot points on a sphere using chromastereoscopic colouring for depth
ss2lcm Load a colourmap into memory.
s2ldev List the available S2PLOT devices on stdout.


Code Example

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

#define NPOINTS 500

void cb(double *time, int *keycount)
/* A callback for determining chromadepth colours based on distance */
{
   static int beenhere = 0;             /* Flag for initialising data */
   static int np = NPOINTS;             /* Number of points */
   static float xpts[NPOINTS], ypts[NPOINTS], zpts[NPOINTS];
   static float dist[NPOINTS];          /* Distance from camera to each point */
   static float size[NPOINTS];          /* Size to draw each point */
   XYZ pos, up, view;                   /* Camera parameters */
   float dmin = 9e30;                   /* Min and max distances */
   float dmax = -9e30;
   int i;

   if (!beenhere) {                     /* Initialise first time through */
      for (i=0;i<np;i++) {
         xpts[i] = drand48()*2.0 - 1.0;
         ypts[i] = drand48()*2.0 - 1.0;
         zpts[i] = drand48()*2.0 - 1.0;
       }
       beenhere = 1;
    }

    ss2qc(&pos, &up, &view, 1);     /* Where is the camera? */

    for (i=0; i< np; i++) {             /* Calculate distance to camera */
       dist[i] = sqrt((xpts[i] - pos.x) * (xpts[i] - pos.x) +
                   (ypts[i] - pos.y) * (ypts[i] - pos.y) +
                   (zpts[i] - pos.z) * (zpts[i] - pos.z));

       dmin = (dist[i] < dmin) ? dist[i] : dmin;
       dmax = (dist[i] > dmax) ? dist[i] : dmax;
    }

    for (i=0; i<np; i++) {              /* Scale sizes */
       size[i] = 8.0 - (dist[i] - dmin) / (dmax - dmin) * 6.0;
    }

    s2chromacpts(np, xpts, ypts, zpts, dist, size, dmin, dmax);
                /* Plot points using chromadepth information */
}

int main(int argc, char **argv)
{
   int nentries;                        /* Number of colour map entries */

   srand48((long)time(NULL));                   /* Seed random numbers */

   fprintf(stderr,"This demonstration appears in 3D when viewed with ");
   fprintf(stderr,"Chromadepth(TM) glasses\n");
   s2opend("/?",argc, argv);                    /* Open the display */
   s2swin(-1.,1., -1.,1., -1.,1.);              /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

/* Load the chromadepth colour map, stored in directory S2PLOT_TEXPATH */
   nentries = ss2lcm("chromapal.txt", 100, 2000);
   s2scir(100, 100+nentries-1);                 /* Set colour range */

   cs2scb(&cb);

   s2show(1);

   return 1;
}



Back to S2PLOT function list.


Personal tools