Newer
Older
* Revision 1.18 2001/02/03 23:43:10 slevy
*
* Don't let "kira tree" hide "kira track" -- demand 3 chars!
*
* Revision 1.17 2001/02/03 16:49:42 slevy
*
* Update cookedcmap when "cment" changes cmap.
*
* Revision 1.15 2001/02/03 14:50:44 slevy
*
* Add "setgamma" (abbr. "setgam" or "cgam") command to adjust colors.
* Add "kira tree {off|on|cross|tick} [tickscale]" subcommand
* for showing tree structure of interacting groups.
*
* Revision 1.14 2001/01/31 17:11:54 slevy
*
* Ensure that, for starlab, clock is always in "continuous" mode.
*
* Revision 1.13 2001/01/31 17:07:12 slevy
*
* Add RCS Id and Log strings.
*
*/
#define __USE_MISC /* makes <math.h> define sqrtf() on GNU libc */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#if !sgi && !defined(sqrtf)
# define sqrtf(x) sqrt(x) /* if no sqrtf() */
#endif
#undef isspace /* hack for irix 6.5 back-compat */
#undef isdigit
#undef isalnum
#if unix
# include <unistd.h>
# include <sys/types.h>
# include <netinet/in.h> /* for htonl */
# ifndef WORDS_BIGENDIAN
# include "config.h" /* for WORDS_BIGENDIAN */
# endif
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#define RGBALPHA(rgb, alpha) ((rgb) | (alpha))
#define RGBWHITE 0xFFFFFF00
#define PACKRGBA(r,g,b,a) ((r)<<24 | (g)<<16 | (b)<<8 | (a))
#define THRESHBIT PACKRGBA(0,0,0,1)
#else
#define RGBALPHA(rgb, alpha) ((rgb) | ((alpha)<<24))
#define RGBWHITE 0x00FFFFFF
#define PACKRGBA(r,g,b,a) ((a)<<24 | (b)<<16 | (g)<<8 | (r))
#define THRESHBIT PACKRGBA(0,0,0,1)
#endif
#if CAVE
# define CAVEMENU 1
#endif
#include "geometry.h"
#include <GL/gl.h>
#if CAVEMENU
#include <cave_ogl.h>
#include "cavemenu.h"
#include "vd_util.h"
#define IFMENU(x) (x)
#else
#define IFMENU(x)
#endif
#include "shmem.h" /* NewN(), etc. */
#include "futil.h"
#include "specks.h"
#include "textures.h"
#include "findfile.h"
#include "partiviewc.h"
#include "sfont.h"
#include <sys/types.h>
#include <signal.h>
#ifdef sgi
#include <malloc.h> /* for mallinfo(), amallinfo() */
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#endif
/* Star Renderer (.sdb) structure -- from stardef.h */
typedef enum {ST_POINT, ST_BRIGHT_CLOUD ,ST_DARK_CLOUD, ST_BOTH_CLOUD, OFF} stype;
typedef struct {
float x, y, z;
float dx, dy, dz;
float magnitude, radius;
float opacity;
int num;
unsigned short color;
unsigned char group;
unsigned char type;
} db_star;
typedef struct hrec { float t; int num;} hrec_t;
typedef struct mrec { float mass, x, y, z, vx, vy, vz, rho, temp, sfr, gasmass;
int id, token;} mrec_t;
/* end Star Renderer */
#define VDOT( v1, v2 ) ( (v1)->x[0]*(v2)->x[0] + (v1)->x[1]*(v2)->x[1] + (v1)->x[2]*(v2)->x[2] )
#if CAVEMENU
int parti_menuwall, parti_menubox[4];
static MenuHead *pmenu = NULL;
static MenuHead *stubmenu = NULL;
struct ments {
MenuEnt *alpha, *point, *poly, *label, *psize, *polysize, *fog;
MenuEnt *step, *fwd, *lumvar, *slum, *colorvar, *where[4];
MenuEnt *viewall, *setscale, *speed, *fspeed, *every;
MenuEnt *seedata, *box, *boxlevel[12];
MenuEnt *annot;
MenuEnt *tknob[3];
MenuEnt *menu;
} ment;
struct boxleveler {
struct stuff *st;
int level;
};
void set_tknob( float val, MenuEnt *me, void *st );
void set_psize( float psize, MenuEnt *me, void *st );
void set_polysize( float psize, MenuEnt *me, void *st );
void set_alpha( float alpha, MenuEnt *me, void *st );
void set_point( int on, MenuEnt *me, void *st );
void set_poly( int on, MenuEnt *me, void *st );
void set_label( int on, MenuEnt *me, void *st );
void set_step( float time0, MenuEnt *me, void *st );
void set_fwd( int fwd, MenuEnt *me, void *st );
void set_slum( float slum, MenuEnt *me, void *st );
void set_lumvar( int which, MenuEnt *me, void *st );
void set_colorvar( int which, MenuEnt *me, void *st );
void set_seedata( int which, MenuEnt *me, void *st );
void set_speed( float speed, MenuEnt *me, void *st );
void set_fspeed( float fspeed, MenuEnt *me, void *st );
void set_every( float every, MenuEnt *me, void *st );
void set_scale( float logscale, MenuEnt *me, void *st );
void set_viewall( int all, MenuEnt *me, void *st );
void set_allboxes( int on, MenuEnt *me, void *st );
void set_boxlevel( int on, MenuEnt *me, void *bleveler );
void set_where( int unused, MenuEnt *me, void *st );
void set_menu( int on, MenuEnt *me, void *st );
#endif /*CAVEMENU*/
static int defcmap[] = {
0x11eeee00,
0x1106ee00, 0x120ea900, 0x1316ce00, 0x1520d500, 0x172ece00, 0x193fcb00,
0x1c54b400, 0x206da400, 0x24889200, 0x2aa58400, 0x33c07600, 0x3ed96a00,
0x4eed6100, 0x63fa5a00, 0x7efe5100, 0x99fb4c00, 0xafef4700, 0xc0dc4000,
0xcbc33900, 0xd4a83000, 0xda8b2900, 0xdf702700, 0xe2572500, 0xe5411700,
0xe82f1000, 0xea211500, 0xeb171400, 0xed0f1200, 0xee0aee00,
0xffffff00,
};
int orientboxcolor = PACKRGBA( 0xff, 0xff, 0, 0xff );
void specks_read( struct stuff **stp, char *fname );
void specks_read_boxes( struct stuff *st, char *fname, int timestep );
int specks_add_box( struct stuff *st, struct AMRbox *box, int timestep );
int specks_purge( void *vstuff, int nbytes, void *aarena );
int specks_count( struct specklist *head );
int specks_gobox( struct stuff *st, int boxno, int argcrest, char *argvrest[] );
int specks_cookcment( struct stuff *st, int cment );
void specks_rgbremap( struct stuff *st );
struct specklist **specks_find_annotation( struct stuff *, struct specklist **);
void specks_set_current_annotation( struct stuff *st, char *annotation );
void specks_add_annotation( struct stuff *st, char *annotation, int timestep );
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
static char separ[] = " \t\n";
void strncpyt( char *dst, char *src, int dstsize ) {
int len = strlen(src);
if(len >= dstsize) len = dstsize-1;
memcpy(dst, src, len);
dst[len] = '\0';
}
#ifdef sgi
static float defgamma = 1.0;
#else
static float defgamma = 2.5;
#endif
struct stuff *
specks_init( int argc, char *argv[] )
{
int i;
struct stuff *st = NewN( struct stuff, 1 );
char *menuopt;
memset(st, 0, sizeof(*st));
st->spacescale = 1.0;
st->fog = 0;
st->psize = 1;
st->alpha = .5;
st->gamma = defgamma;
st->rgbgamma[0] = st->rgbgamma[1] = st->rgbgamma[2] = 1.0;
st->rgbright[0] = st->rgbright[1] = st->rgbright[2] = 1.0;
specks_rgbremap( st );
st->useme = 1;
st->usepoly = 0;
st->usepoint = 1;
st->usetext = 1;
st->usetextaxes = 1;
st->usetextures = 1;
st->useboxes = 1;
st->polysizevar = -1;
st->polyarea = 0;
st->polyorivar0 = -1;
st->texturevar = -1;
st->txscale = .5;
st->boxlabels = 0;
st->boxlabelscale = 1.0;
st->boxlevelmask = ~0; /* all levels on */
st->boxaxes = 0; /* boxes don't show orientation markers */
st->goboxscale = 1.0;
st->textsize = .05;
st->npolygon = 11;
st->subsample = 1;
st->menudemandfps = 4.0;
st->pfaint = .05; /* params for "fast" point-drawing */
st->plarge = 10;
st->polymin = .5; /* don't draw polygons if smaller (pixels) */
st->polymax = 2048; /* don't allow polygons to get bigger than this (pixels) */
st->textmin = 2; /* replace labels with line-segments if smaller (pixels) */
st->ntextures = 0;
st->textures = NULL;
st->fade = F_SPHERICAL;
st->fadeknee1 = 10.0;
st->fadeknee2 = 1.0;
st->knee2steep = 1.0;
st->gscale = 1.;
st->gtrans.x[0] = st->gtrans.x[1] = st->gtrans.x[2] = 0;
st->objTo2w = Tidentity;
st->ncmap = st->boxncmap = COUNT(defcmap);
st->cmap = NewN(int, COUNT(defcmap));
st->sizedby = 0;
st->coloredby = 1;
st->sizeseq = st->colorseq = st->threshseq = 0;
st->trueradius = 0;
st->sdbvars = shmstrdup( "mcr" );
st->ntimes = 0;
st->ndata = 0;
st->curtime = 0;
st->curdata = 0;
st->datatime = 0;
st->usertrange = 0;
st->utmin = -HUGE;
st->utmax = HUGE;
st->utwrap = 0.1;
st->sl = NULL;
st->boxes = NULL;
st->boxlevels = 0;
st->boxlinewidth = 0.75;
st->clk = NewN(SClock, 1);
clock_init(st->clk);
clock_set_running(st->clk, 1);
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
memset(st->anima, 0, sizeof(st->anima));
memset(st->annot, 0, sizeof(st->annot));
memset(st->datafile, 0, sizeof(st->datafile));
memset(st->fname, 0, sizeof(st->fname));
#if CAVE
shmrecycler( specks_purge, st );
#endif
for(i = 1; i < argc; i++)
specks_read( &st, argv[i] );
#if CAVEMENU
menu_preinit();
pmenu = menu_create( .05, .95 );
menu_setfont( pmenu, font_small );
ment.annot = menu_addentry( pmenu, " ", NULL, NULL );
menu_addentry( pmenu, " ", NULL, NULL );
menuopt = getenv("PARTIMENU");
if(menuopt == NULL) menuopt = "label";
if(strstr(menuopt, "survey")) { /* SC99DEMO star-formation survey */
for(i = 0; i < 3; i++) {
struct boxleveler *tb = NewN( struct boxleveler, 1 );
tb->st = st;
tb->level = i;
ment.tknob[i] = menu_addknob( pmenu, NULL, set_tknob, 0, 0,4, tb );
}
}
menu_addentry( pmenu, " ", NULL, NULL );
ment.psize = menu_addknob( pmenu, NULL, set_psize, st->psize, 0.1,20, st );
ment.slum = menu_addknob( pmenu, NULL, set_slum,
st->vdesc[st->curdata][st->sizedby].lum, .1, 10, st );
ment.lumvar = menu_addtoggle( pmenu, NULL, set_lumvar, st->sizedby, MAXVAL, st );
ment.colorvar = menu_addtoggle( pmenu, NULL, set_colorvar, st->coloredby, MAXVAL, st );
ment.seedata = menu_addtoggle( pmenu, NULL, set_seedata, st->curdata, 2, st );
if(strstr(menuopt, "label"))
ment.label = menu_addtoggle( pmenu, NULL, set_label, st->usetext, 2, st );
if(strstr(menuopt, "poly"))
ment.poly = menu_addtoggle( pmenu, NULL, set_poly, st->usepoly, 2, st );
menu_addentry( pmenu, " ", NULL, NULL ); /* spacer */
#ifndef STATIC_SPECKS
ment.fspeed = menu_addknob( pmenu, NULL, set_fspeed, clock_speed(st->clk), 0, 5, st );
ment.speed = menu_addknob( pmenu, NULL, set_speed, clock_speed(st->clk), .5, 5, st );
ment.step = menu_addknob( pmenu, NULL, set_step, clock_time(st->clk), 0, 10, st );
ment.fwd = menu_addtoggle( pmenu, NULL, set_fwd, clock_fwd(st->clk), 2, st );
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#endif
#ifndef NO_WHERE
ment.where[0] = menu_addentry( pmenu, "", NULL, NULL );
ment.where[1] = menu_addentry( pmenu, "", NULL, NULL );
ment.where[2] = menu_addentry( pmenu, "", NULL, NULL );
ment.where[3] = menu_addentry( pmenu, "", NULL, NULL );
#endif
ment.every = menu_addknob( pmenu, NULL, set_every, st->subsample, 1, 10, st );
menu_addentry( pmenu, " ", NULL, NULL );
ment.setscale = menu_addknob( pmenu, NULL, set_scale, 0., -4., 1., st );
if(strstr(menuopt, "viewall"))
ment.viewall = menu_addtoggle( pmenu, NULL, set_viewall, 0, 2, st );
menu_addentry( pmenu, " ", NULL, NULL );
ment.box = menu_addtoggle( pmenu, NULL, set_allboxes, st->useboxes, 3, st );
menu_addentry( pmenu, " ", NULL, NULL );
{
struct boxleveler *blev = NewN( struct boxleveler, COUNT(ment.boxlevel) );
for(i = 0; i < COUNT(ment.boxlevel); i++) {
blev[i].st = st;
blev[i].level = i;
ment.boxlevel[i] = menu_addtoggle( pmenu, NULL, set_boxlevel, 1, 2,
&blev[i] );
}
}
ment.menu = menu_addtoggle( pmenu, "<Menu>", set_menu, 0, 2, st );
menu_addentry( pmenu, " ", NULL, NULL );
stubmenu = menu_create( .05, .15 );
menu_addtoggle( stubmenu, "<Menu>", set_menu, 0, 2, st );
menu_sethidden( stubmenu, 1 );
#endif /*NOCAVE*/
return st;
}
#if CAVEMENU
void specks_refresh_menu(struct stuff *st)
{
int i;
#if MENU_IN_PPR
menu_check( pmenu, pmenu->cavewall );
menu_check( stubmenu, stubmenu->cavewall );
#endif
menu_sethidden( pmenu, st->hidemenu || empty );
menu_sethidden( stubmenu, st->hidemenu<=0 || empty );
if(st->vdcmd[0] != '\0') {
VIDI_queue_commandstr( st->vdcmd );
st->vdcmd[0] = '\0';
}
set_psize( st->psize, ment.psize, st );
set_lumvar( st->sizedby, ment.lumvar, st );
set_colorvar( st->coloredby, ment.colorvar, st );
set_slum( st->vdesc[st->curdata][st->sizedby].lum, ment.slum, st );
set_every( st->subsample, ment.every, st );
set_scale( ment.setscale->val, ment.setscale, st );
if(ment.label) set_label( st->usetext, ment.label, st );
if(ment.poly) set_poly( st->usepoly, ment.poly, st );
if(ment.annot)
menu_settitle( ment.annot, st->annotation ? st->annotation : " " );
if(st->ntimes > 1) {
menu_setknobrange( ment.step, 0, st->ntimes-1 );
set_fwd( st->timefwd, ment.fwd, st );
set_step( st->time0, ment.step, st );
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
} else {
menu_settitle( ment.fwd, "" );
menu_settitle( ment.step, "" );
menu_settitle( ment.speed, "" );
if(ment.viewall)
menu_settitle( ment.viewall, "" ); /* no need to "view peak", right? */
}
if(st->ndata > 1) {
set_seedata( st->curdata, ment.seedata, st );
} else {
menu_settitle( ment.seedata, "" );
}
if(st->boxlevels > 0) {
set_allboxes( st->useboxes, ment.box, st );
} else {
menu_settitle( ment.box, "" );
}
if(ment.tknob[0]) /* if SC99DEMO, i.e. if PARTIMENU includes "survey" */
for(i = 0; i < 3; i++)
set_tknob( ment.tknob[i]->val, ment.tknob[i], ment.tknob[i]->data );
#ifndef NO_WHERE
for(i = 0; i < COUNT(ment.where) && ment.where[i] != NULL; i++)
set_where( i, ment.where[i], st );
#endif
/* Publicize our menu location so other apps -- Matt's vtk AMR code --
* can avoid interacting if user's wand points there.
*/
parti_menuwall = pmenu->cavewall;
parti_menubox[0] = pmenu->x0 * pmenu->wallxpix;
parti_menubox[1] = ((pmenu->y0 < pmenu->y1) ? pmenu->y0 : pmenu->y1)
* pmenu->wallypix;
parti_menubox[2] = pmenu->x1 * pmenu->wallxpix;
parti_menubox[3] = ((pmenu->y0 > pmenu->y1) ? pmenu->y0 : pmenu->y1)
* pmenu->wallypix;
}
void specks_evoke_menu( struct stuff *st ) {
menu_evoke( pmenu ); /* evoke any callbacks */
}
#endif /*CAVEMENU*/
void specks_rethresh( struct stuff *st, struct specklist *sl, int by )
{
struct valdesc *vd;
int i;
int curdata = st->curdata;
int nel = sl->nspecks;
float cmin, cmax, normal;
int ncmap = st->ncmap;
int index;
int min, max;
float threshmin = st->thresh[0], threshmax = st->thresh[1];
struct speck *p = sl->specks;
sl->threshseq = st->threshseq;
if(sl->text != NULL) /* specklists with labels shouldn't be thresholded */
return;
if(curdata >= st->ndata)
curdata = 0;
min = (SMALLSPECKSIZE(by)>=sl->bytesperspeck) ? 0 : st->usethresh&P_THRESHMIN;
max = (SMALLSPECKSIZE(by)>=sl->bytesperspeck) ? 0 : st->usethresh&P_THRESHMAX;
for(i = 0, p = sl->specks; i < sl->nspecks; i++, p = NextSpeck( p, sl, 1 )) {
p->rgba = (min&&p->val[by]<threshmin) || (max&&p->val[by]>threshmax)
? p->rgba | THRESHBIT : p->rgba & ~THRESHBIT;
}
}
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
int specks_cookcment( struct stuff *st, int cment )
{
unsigned char crgba[4];
memcpy(crgba, &cment, 4); /* XXX 64-bit bug? */
return (cment & ~RGBWHITE) |
PACKRGBA(
st->rgbmap[0][crgba[0]],
st->rgbmap[1][crgba[1]],
st->rgbmap[2][crgba[2]],
0 );
}
void specks_rgbremap( struct stuff *st )
{
int i, k;
for(i = 0; i < 256; i++) {
float t = (float)i / 256;
float v = 255.99f * pow(t, 1/st->rgbgamma[0]);
k = (int) (st->rgbright[0] * v);
st->rgbmap[0][i] = (k <= 0) ? 0 : (k > 255) ? 255 : k;
if(st->rgbgamma[0] != st->rgbgamma[1])
v = 255.99f * pow(t, 1/st->rgbgamma[1]);
k = (int) (st->rgbright[1] * v);
st->rgbmap[1][i] = (k <= 0) ? 0 : (k > 255) ? 255 : k;
if(st->rgbgamma[1] != st->rgbgamma[2])
v = 255.99f * pow(t, 1/st->rgbgamma[2]);
k = (int) (st->rgbright[2] * v);
st->rgbmap[2][i] = (k <= 0) ? 0 : (k > 255) ? 255 : k;
}
/* remake colormap too */
for(i = 0; i < st->ncmap; i++)
st->cookedcmap[i] = specks_cookcment( st, st->cmap[i] );
st->colorseq++;
}
void specks_recolor( struct stuff *st, struct specklist *sl, int by )
{
struct valdesc *vd;
int i;
int curdata = st->curdata;
int nel = sl->nspecks;
struct speck *sp = sl->specks;
float cmin, cmax, normal;
int ncmap = st->ncmap;
int index;
int rgb565;
sl->coloredby = by;
sl->colorseq = st->colorseq;
if(sl->text != NULL) /* specklists with labels shouldn't be recolored */
return;
if(curdata >= st->ndata)
curdata = 0;
if(by == CONSTVAL) {
/* Hack -- color by given RGB value */
char crgba[4];
r = (vd->cmin<=0) ? 0 : vd->cmin>=1 ? 255 : (int)(255.99f * vd->cmin);
g = (vd->cmax<=0) ? 0 : vd->cmax>=1 ? 255 : (int)(255.99f * vd->cmax);
b = (vd->mean<=0) ? 0 : vd->mean>=1 ? 255 : (int)(255.99f * vd->mean);
crgba[0] = st->rgbmap[0][r];
crgba[1] = st->rgbmap[0][g];
crgba[2] = st->rgbmap[0][b];
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
for(i = 0; i < nel; i++, sp = NextSpeck(sp, sl, 1)) {
sp->rgba = rgba | (sp->rgba & THRESHBIT);
}
return;
}
if(by >= MAXVAL || by < 0 || SMALLSPECKSIZE(by) > sl->bytesperspeck)
by = 0;
vd = &st->vdesc[curdata][by];
cmin = vd->cmin, cmax = vd->cmax;
if(cmin == cmax && cmin == 0 || (vd->call && !vd->cexact)) {
vd->cmin = cmin = vd->min;
vd->cmax = cmax = vd->max;
}
normal = (cmax != cmin && ncmap>2) ? (ncmap-2)/(cmax - cmin) : 0;
rgb565 = !strcmp(vd->name, "rgb565") || !strcmp(vd->name, "colors565");
/* cexact field means:
* 0 (default): scale data range to cmap index 1..ncmap-2;
* use 0 and ncmap-1 for low- and high- out-of-range values.
*
* 1 ("exact"): use data value as literal colormap index, 0..ncmap-1.
*/
for(i = 0; i < nel; i++, sp = NextSpeck(sp, sl, 1)) {
if(rgb565) {
index = sp->val[by];
sp->rgba = PACKRGBA(
rgbmap[0][(index&0xF800)>>(11-(8-5))],
rgbmap[1][(index&0x07E0)>>(5-(8-6))],
rgbmap[2][(index&0x1F)<<(8-5)],
0 )
| (sp->rgba & THRESHBIT);
} else {
index = vd->cexact ? sp->val[by] + cmin
: (sp->val[by] - cmin) * normal + 1;
if(index < 0) index = 0;
else if(index >= ncmap) index = ncmap-1;
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
}
}
}
void specks_resize( struct stuff *st, struct specklist *sl, int by )
{
int i;
int nel = sl->nspecks;
struct speck *sp = sl->specks;
int curdata = st->curdata;
struct valdesc *vd;
float lmin, lmax, normal;
sl->sizedby = by;
sl->sizeseq = st->sizeseq;
if(sl->text != NULL) /* specklists with labels shouldn't be resized */
return;
if(curdata < 0 || curdata >= st->ndata)
curdata = 0;
if(by == CONSTVAL) {
vd = &st->vdesc[curdata][CONSTVAL];
for(i = 0; i < nel; i++, sp = NextSpeck(sp, sl, 1))
sp->size = vd->lmin;
return;
}
if(by < 0 || by >= MAXVAL)
by = 0;
vd = &st->vdesc[curdata][by];
lmin = vd->lmin, lmax = vd->lmax;
if(lmin == lmax && lmin == 0 || vd->lall) {
vd->lmin = lmin = vd->min;
vd->lmax = lmax = vd->max;
}
if(lmax == lmin)
normal = 1;
else
normal = 1 / (lmax - lmin);
for(i = 0; i < nel; i++, sp = NextSpeck(sp, sl, 1))
sp->size = (sp->val[by] - lmin) * normal;
}
void specks_datawait(struct stuff *st) {
#if USE_IEEEIO
while(st->fetching && st->fetchpid > 0
&& st->fetchtime == st->curtime
&& st->fetchdata == st->curdata)
usleep(50000);
#endif
}
#ifdef USE_IEEEIO
void specks_ieee_server( void *vst ) {
struct stuff *st = (struct stuff *)vst;
struct specklist *sl;
prctl(PR_TERMCHILD); /* Die when parent dies */
/* Await a request */
for(;;) {
time_t then;
while(st->fetching <= 0)
sginap(5);
then = time(NULL);
sl = specks_ieee_read_timestep( st, st->subsample,
st->fetchdata, st->fetchtime );
if(then + 5 < time(NULL))
msg("... got %x (%d particles) from %s", sl, specks_count(sl),
st->fname[st->fetchdata][st->fetchtime]);
if(st->curtime == st->fetchtime && st->curdata == st->fetchdata
&& sl != NULL) {
st->sl = sl;
parti_redraw();
}
st->fetching = 0;
}
}
#endif /*USE_IEEEIO*/
/* ignore it! */
/* or maybe use fspeed to specify finite clock resolution */
void specks_shift_ghosts( struct stuff *st ) {
int i;
struct specklist **slp =
specks_timespecksptr( st, 0,
st->nghosts > 0 ? st->nghosts-1 : 0 );
if(slp && *slp)
specks_discard( st, slp );
for(i = st->nghosts; --i > 0; ) {
slp = specks_timespecksptr( st, 0, st->nghosts );
*slp = slp[-1];
}
*specks_timespecksptr( st, 0, 0 ) = NULL;
}
{
struct specklist *sl = st->sl;
struct specklist **slp;
if(st->usertrange) {
if(tmin < st->utmin) tmin = st->utmin;
if(tmax > st->utmax) tmax = st->utmax;
}
clock_set_range( st->clk, tmin, tmax, st->utwrap );
/* Possibly retain old snapshots -- up to st->ntimes of them! */
/* In any case, discard previous array */
specks_shift_ghosts( st );
/* Hack for kira-parti dynamic data */
if(sl) {
if(st->coloredby >= 0 && st->coloredby < CONSTVAL)
st->colorseq++;
if(st->sizedby >= 0 && st->coloredby < CONSTVAL)
st->sizeseq++;
if(st->threshvar >= 0)
st->threshseq++;
}
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
if(timestep < 0) timestep = 0;
slp = specks_timespecksptr( st, st->curdata, timestep );
if(*slp != NULL && (*slp)->subsampled > st->subsample) {
specks_discard( st, slp );
}
sl = *slp;
#ifdef USE_IEEEIO
if(sl == NULL && (st->fetching == 0 || st->datasync)
&& st->curdata>=0 && st->curdata<st->ndata
&& st->datafile[st->curdata] != NULL
&& timestep>=0 && timestep<st->ntimes
&& st->datafile[st->curdata][timestep] != NULL) {
st->fetchdata = st->curdata;
st->fetchtime = timestep;
if(getenv("NO_SPROC") || st->datasync) {
sl = specks_ieee_read_timestep( st, st->subsample,
st->fetchdata, st->fetchtime );
msg("Got %x (%d particles) from %s (d%d t%d)\n",
sl, specks_count(sl), st->fname[st->fetchdata][st->fetchtime],
st->fetchdata, st->fetchtime);
} else {
st->fetching = 1;
if(st->fetchpid <= 0) {
st->fetchpid = sproc( specks_ieee_server, PR_SADDR|PR_SFDS, st );
if(st->fetchpid < 0)
perror("sproc");
}
}
}
if(st->fetchpid > 0) {
if(kill(st->fetchpid, 0) < 0) {
perror("specks server vanished: kill -0");
st->fetching = 0;
st->fetchpid = 0;
}
}
#endif /*USE_IEEEIO*/
if(sl == NULL && !(st->boxtimes>timestep && st->boxes[timestep]!=NULL))
return;
st->sl = sl; /* st->sl <= anima[][] */
st->curtime = timestep;
#if !CAVEMENU
st->frame_time = st->curtime; /* if non-CAVE, we have no frame-function */
#endif
specks_set_current_annotation( st, st->annot[st->curdata][st->curtime]
? st->annot[st->curdata][st->curtime]->text : NULL );
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
}
void specks_set_current_annotation( struct stuff *st, char *annotation )
{
st->annotation = annotation;
#ifdef CAVEMENU
if(ment.annot)
menu_settitle( ment.annot, st->annotation ? st->annotation : "" );
#endif
}
void specks_add_annotation( struct stuff *st, char *annotation, int timestep )
{
struct specklist *sl, **slp;
int curtime = (timestep < 0) ? st->curtime : timestep;
if(annotation == NULL) annotation = "";
specks_timespecksptr( st, st->curdata, curtime );
if(curtime >= st->ntimes) curtime = 0;
slp = &st->annot[st->curdata][curtime];
if((sl = *slp) == NULL) {
sl = *slp = NewN( struct specklist, 1 );
memset(*slp, 0, sizeof(**slp));
} else if(sl->text) {
Free(sl->text);
}
sl->text = NewN( char, strlen(annotation)+1 );
strcpy( sl->text, annotation );
}
void starswap(db_star *st) {
int i, *wp;
/* byte-swap x,y,z, dx,dy,dz, magnitude,radius,opacity fields (32-bit float),
* num (32-bit int),
* color (16-bit short).
* group and type fields shouldn't need swapping,
* assuming the compiler packs bytes into a word in increasing
* address order. Seems safe.
*/
for(i = 0, wp = (int *)st; i < 10; i++)
wp[i] = htonl(wp[i]);
st->color = htons(st->color);
}
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
void specks_read_sdb( struct stuff *st, char *sdbfname, int timestep )
{
FILE *inf = fopen(sdbfname, "r");
long flen;
int nspecks, i;
float min[MAXVAL], max[MAXVAL], sum[MAXVAL];
struct specklist *sl, **slp;
register struct speck *sp;
int dfltvars = (strcmp(st->sdbvars, "mcr") == 0);
int nvars = strlen(st->sdbvars);
int needswap = (htonl(1) != 1);
if(inf == NULL) {
msg("sdb: %s: cannot open: %s", sdbfname, strerror(errno));
return;
}
/* Just measure file size */
errno = 0;
fseek(inf, 0, SEEK_END);
flen = ftell(inf);
if(flen == -1 || flen == 0) {
msg("sdb: %s: can't measure length of file: %s", sdbfname, strerror(errno));
return;
}
nspecks = (flen / sizeof(db_star));
if(nspecks <= 0) {
msg("sdb: %s: ignoring empty sdb file", sdbfname);
return;
}
sl = NewN(struct specklist, 1);
memset(sl, 0, sizeof(*sl));
sl->bytesperspeck = SMALLSPECKSIZE( nvars );
if(nvars > MAXVAL) nvars = MAXVAL;
sl->scaledby = st->spacescale;
sp = NewNSpeck(sl, nspecks);
sl->specks = sp;
fseek(inf, 0, SEEK_SET);
for(i = 0; i < nspecks; i++, sp = NextSpeck(sp, sl, 1)) {
db_star star;
char *cp;
int k;
float *vp;
if(fread(&star, sizeof(star), 1, inf) <= 0)
break;
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
starswap(&star);
#endif
sp->p.x[0] = star.x * sl->scaledby;
sp->p.x[1] = star.y * sl->scaledby;
sp->p.x[2] = star.z * sl->scaledby;
if(dfltvars) {
sp->val[0] = exp((-18-star.magnitude)*.921/*log(100)/5*/);
sp->val[1] = star.color;
sp->val[2] = star.radius;
} else {
for(vp = &sp->val[0], cp = st->sdbvars; *cp; cp++, vp++) {
switch(*cp) {
case 'm': *vp = exp((-18-star.magnitude)*.921/*log(100)/5*/); break;
case 'M': *vp = star.magnitude; break;
case 'c': *vp = star.color; break;
case 'r': *vp = star.radius; break;
case 'o': *vp = star.opacity; break;
case 'g': *vp = star.group; break;
case 't': *vp = star.type; break;
case 'x': *vp = star.dx; break;
case 'y': *vp = star.dy; break;
case 'z': *vp = star.dz; break;
case 'S': *vp = sqrt(star.dx*star.dx + star.dy*star.dy + star.dz*star.dz); break;
case 'n': *vp = star.num; break;
default: *vp = 1; break;
}
}
}
if(i == 0) {
for(k = 0; k < nvars; k++)
sum[k] = min[k] = max[k] = sp->val[k];
} else {
for(k = 0; k < nvars; k++) {
if(min[k] > sp->val[k]) min[k] = sp->val[k];
else if(max[k] < sp->val[k]) max[k] = sp->val[k];
sum[k] += sp->val[k];
}
}