Function:ss2lcm
From S2PLOT
(Difference between revisions)
Revision as of 01:58, 28 October 2007 S2plot admin (Talk | contribs) ← Previous diff |
Current revision S2plot admin (Talk | contribs) |
Current revision
ss2lcm
Load a colourmap into memory.
Prototype
int ss2lcm(char *imapfile, int startidx, int maxn);
Description
Load a colourmap into memory, starting at index startidx, read a maximum of maxn colours. Returns the number of entries read and stored. Map file format is per line:
index red green blue
with all integer values. Colour components are in the range [0,255]. The imapfile containing the colourmap should be stored in the directory pointed to by the environment variable S2PLOT_TEXPATH The index column is currently ignored. After calling this function, it is usual to call s2scir(startidx, startidx+retval-1) to activate this colormap for subsequent use.
See Also
struct_COLOUR | Data structure for (r,g,b) colour indices. |
s2icm | Install various colour maps. |
s2scir | Set the range of colour indices used for shading. |
s2chromapts | Plot points on a sphere using chromastereoscopic colouring for depth |
s2chromacpts | Plot cartesian points using chromastereoscopic colouring for depth |
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.