Newer
Older
}
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);
if(st->useemph && st->emphsel.use != SEL_NONE) {
for(i = 0; i < nel; i++, sp = NextSpeck(sp, sl, 1)) {
sp->size = (sp->val[by] - lmin) * normal;
if(SELECTED(sl->sel[i], &st->emphsel)) {
sp->size *= st->emphfactor;
}
} else {
/* normal case */
for(i = 0; i < nel; i++, sp = NextSpeck(sp, sl, 1))
sp->size = (sp->val[by] - lmin) * normal;
}
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
}
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*/
void specks_set_timebase( struct stuff *st, double timebase ) {
clock_set_timebase( st->clk, timebase );
/* parti_set_timebase( st, timebase ); */
}
/* ignore it! */
/* or maybe use fspeed to specify finite clock resolution */
{
struct specklist *sl = st->sl;
struct specklist **slp;
tmin = st->clk->tmin;
tmax = st->clk->tmax;
/*if(tmin < st->utmin)*/ tmin = st->utmin;
/*if(tmax > st->utmax)*/ tmax = st->utmax;
/* Only expand clock's existing time range */
if(tmin > st->clk->tmin) tmin = st->clk->tmin;
if(tmax < st->clk->tmax) tmax = st->clk->tmax;
clock_set_range( st->clk, tmin, tmax, st->utwrap );
if(st->dyn.enabled && st->dyn.getspecks) {
sl = (*st->dyn.getspecks)(&st->dyn, st, realtime);
if(sl == NULL)
return;
/* Do we need this? */ /* *slp = sl; */ /* Guess not... */
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
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(st->skipblanktimes
&& sl == NULL
&& !(st->boxtimes>timestep && st->boxes[timestep]!=NULL)
&& st->meshes[st->curdata][timestep] == NULL)
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
{ struct specklist *asl = CURDATATIME(annot);
specks_set_current_annotation( st, asl ? asl->text : NULL );
}
}
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]; /* safe -- no need for CURDATATIME() check */
if((sl = *slp) == NULL) {
sl = *slp = NewN( struct specklist, 1 );
memset(*slp, 0, sizeof(**slp));
sl->speckseq = ++st->speckseq;
} 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);
}
void specks_read_sdb( struct stuff *st, char *sdbfname, int timestep )
{
FILE *inf = fopen(sdbfname, "rb");
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
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);
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->speckseq = ++st->speckseq;
sl->bytesperspeck = SMALLSPECKSIZE( nvars );
if(nvars > MAXVAL) nvars = MAXVAL;
sl->scaledby = st->spacescale;
sp = NewNSpeck(sl, nspecks);
sl->specks = sp;
sl->sel = NewN( SelMask, nspecks );
sl->nsel = nspecks;
memset(sl->sel, 0, nspecks*sizeof(SelMask));
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;
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
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];
}
}
}
sl->nspecks = i;
sl->sizedby = 0;
sl->coloredby = 1;
/* Update statistics */
if(sl->nspecks > 0) {
struct valdesc *vdp = &st->vdesc[st->curdata][0];
for(i = 0; i < nvars; i++, vdp++) {
if(vdp->min > min[i]) vdp->min = min[i];
if(vdp->max < max[i]) vdp->max = max[i];
vdp->nsamples += sl->nspecks;
vdp->sum += sum[i];
vdp->mean = vdp->sum / vdp->nsamples;
if(vdp->name[0] == '\0') {
char *name = "unk";
switch(st->sdbvars[i]) {
case 'm': name = "lumsdb"; break;
case 'M': name = "magsdb"; break;
case 'c': name = vdp->max > 16384 ? "rgb565" : "colorsdb";
vdp->cexact = 1;
break;
case 'r': name = "radius"; break;
case 'o': name = "opacity"; break;
case 'g': name = "group"; break;
case 't': name = "type"; break;
case 'x': name = "dx"; break;
case 'y': name = "dy"; break;
case 'z': name = "dz"; break;
case 'S': name = "speed"; break;
case 'n': name = "number"; break;
}
strcpy(vdp->name, name);
}
}
specks_recolor( st, sl, st->coloredby );
specks_resize( st, sl, st->sizedby );
}
/* Add to running list */
slp = specks_timespecksptr( st, st->curdata, timestep );
sl->next = *slp;
*slp = sl;
fclose(inf);
}
if(st->dyn.enabled && st->dyn.trange &&
(*st->dyn.trange)(&st->dyn, st, tminp, tmaxp)) {
/* OK */
} else {
*tmaxp = (st->ntimes == 0) ? 0 : st->ntimes - 1;
}
int specks_get_datastep( struct stuff *st )
{
return st->curtime;
}
double specks_get_realtime( struct stuff *st )
{
return st->currealtime;
}
void set_interest_point( Point *p )
{
#if CAVEMENU
char cmd[80];
sprintf(cmd, "interest %g %g %g", p->x[0], p->x[1], p->x[2]);
VIDI_queue_commandstr( cmd );
#else
parti_center( p );
#endif
}
/* Only specks_timespecksptr() extends the spans of time or datasets */
struct specklist **
specks_timespecksptr( struct stuff *st, int dataset, int timestep )
{
int d, needroom;
struct specklist **na, **nan;
void **ndf;
char **nfn;
if((timestep >= st->ntimes || dataset >= st->ndata)) {
needroom = st->timeroom;
if(timestep >= st->timeroom)
needroom = 2*timestep + 15;
for(d = 0; d < st->ndata || (dataset < MAXFILES && d <= dataset); d++) {
if(needroom == st->timeroom && d < st->ndata)
continue;
na = NewN( struct specklist *, needroom );
nan = NewN( struct specklist *, needroom );
ndf = NewN( void *, needroom );
nfn = NewN( char *, needroom );
nmesh = NewN( struct mesh *, needroom );
memset(na, 0, needroom * sizeof(*na));
memset(nan, 0, needroom * sizeof(*nan));
memset(ndf, 0, needroom * sizeof(*ndf));
memset(nfn, 0, needroom * sizeof(*nfn));
memset(nmesh, 0, needroom * sizeof(*nmesh));
if(d < st->ndata && st->anima[d])
memcpy( na, st->anima[d], st->ntimes * sizeof(*na) );
if(d < st->ndata && st->annot[d])
memcpy( nan, st->annot[d], st->ntimes * sizeof(*nan) );
if(d < st->ndata && st->datafile[d])
memcpy( ndf, st->datafile[d], st->ntimes * sizeof(*ndf) );
if(d < st->ndata && st->fname[d])
memcpy( nfn, st->fname[d], st->ntimes * sizeof(*nfn) );
if(d < st->ndata && st->meshes[d])
memcpy( nmesh, st->meshes[d], st->ntimes * sizeof(*nfn) );
/* Don't free old pointers, just in case they're in use. */
st->anima[d] = na;
st->annot[d] = nan;
st->datafile[d] = ndf;
st->fname[d] = nfn;
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
}
st->timeroom = needroom;
if(timestep >= st->ntimes)
st->ntimes = timestep + 1;
if(dataset >= st->ndata && dataset < MAXFILES)
st->ndata = dataset + 1;
}
return (timestep >= 0 && timestep < st->ntimes &&
dataset >= 0 && dataset < st->ndata)
? &st->anima[dataset][timestep] : NULL;
}
struct specklist *
specks_timespecks( struct stuff *st, int dataset, int timestep )
{
return (timestep >= 0 && timestep < st->ntimes &&
dataset >= 0 && dataset < st->ndata)
? st->anima[dataset][timestep] : NULL;
}
void specks_reupdate( struct stuff *st, struct specklist *sl )
{
struct specklist *tsl;
if(sl != NULL && sl->threshseq != st->threshseq) {
for(tsl = sl; tsl != NULL; tsl = tsl->next)
specks_rethresh( st, tsl, st->threshvar );
}
if(sl != NULL && sl->colorseq != st->colorseq) {
for(tsl = sl; tsl != NULL; tsl = tsl->next)
specks_recolor( st, tsl, st->coloredby );
}
if(sl != NULL && sl->sizeseq != st->sizeseq) {
for(tsl = sl; tsl != NULL; tsl = tsl->next)
specks_resize( st, tsl, st->sizedby );
}
}
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
static int specks_nonempty_timestep( struct stuff *st, int timestep ) {
if(specks_timespecks( st, st->curdata, timestep ) != NULL)
return 1;
if((st->datafile[st->curdata] != NULL &&
st->datafile[st->curdata][timestep] != NULL))
return 1;
if(timestep >= 0 && timestep < st->ntimes &&
st->meshes[st->curdata][timestep] != NULL)
return 1;
if(timestep >= 0 && timestep < st->boxtimes &&
st->boxes[timestep] != NULL)
return 1;
return 0;
}
clock_set_time( st->clk, newtime );
specks_set_timestep( st );
if(st->sl == NULL && st->ntimes > 1 && st->clk->parent == NULL) {
/* Skip blank time-slots -- keep incrementing until either:
* - we find a time-slot that has (or could have) some data, or
* - we've run through all time-steps (avoid infinite loops!).
*/
int nudges, ts;
if(st->skipblanktimes) {
for(nudges = 0; nudges < st->ntimes; nudges++) {
ts = (st->curtime + nudges) % st->ntimes;
if( specks_nonempty_timestep( st, ts ) )
break;
}
}
clock_set_time( st->clk, ts );
specks_set_timestep( st );
}
/* st->playnext = now + (st->fspeed != 0 ? 1/st->fspeed : 0); */
static Point lastinterest;
if(sl != NULL && memcmp(&sl->interest, &lastinterest, sizeof(Point))
&& (sl->interest.x[0]!=0 || sl->interest.x[1]!=0
|| sl->interest.x[2]!=0)) {
char str[128];
float scale = .004;
lastinterest = sl->interest;
set_interest_point( &lastinterest );
sprintf(str, "\002setjump peak %g %g %g 0 0 0 %g",
lastinterest.x[0], lastinterest.x[1]-scale*5, lastinterest.x[2] + scale*5,
scale);
VIDI_queue_commandstr( str );
}
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
#if CAVE
specks_refresh_menu( st );
#endif
}
static int specks_freenow( struct specklist **slp, int maxage )
{
struct specklist *sl, **sprev;
int any = 0;
for(sprev = slp; (sl = *sprev) != NULL && sl->used <= maxage; ) {
if(sl->used <= maxage) {
*sprev = sl->freelink;
if(sl->specks != NULL)
Free(sl->specks);
Free(sl);
any++;
} else {
/* too recent - might still be in use */
sprev = &sl->freelink;
}
}
return any;
}
void specks_discard( struct stuff *st, struct specklist **slp )
{
struct specklist *sl, *slnext;
for(sl = *slp; sl != NULL; sl = slnext) {
slnext = sl->next;
sl->freelink = st->scrap;
st->scrap = sl;
}
*slp = NULL;
}
int specks_purge( void *vst, int nbytes, void *aarena )
{
struct stuff *st = (struct stuff *)vst;
int oldused = st->used;
int oldtime = -1, oldds = -1;
int t, ds;
struct specklist *sl;
#ifdef sgi
static int first = 1;
struct mallinfo mi;
mi = amallinfo( aarena );
if(first) {
first = 0;
msg("Purging %dKbyte shmem arena (currently %dK used in %d blks, %dK free)\n",
mi.arena>>10, mi.uordblks>>10, mi.ordblks, mi.fordblks>>10);
}
#endif
/* Free any known scrap first */
#define OLD_ENOUGH 4
if(specks_freenow( &st->scrap, st->used - OLD_ENOUGH ) > 0)
return 1;
for(t = 0; t < st->ntimes; t++) {
if(t == st->curtime) continue;
for(ds = 0; ds < st->ndata; ds++) {
sl = st->anima[ds][t];
if(sl != NULL && sl != st->sl && sl->used < oldused) {
oldused = st->used;
oldtime = t;
oldds = ds;
}
}
}
if(oldtime >= 0) {
specks_discard( st, &st->anima[oldds][oldtime] );
specks_freenow( &st->scrap, oldtime );
return 1; /* We freed something, so try allocating again */
} else {
msg("Ran out of shmem, couldn't find anything more to purge\n");
#ifdef sgi
msg("%dKbyte shmem arena (currently %dK used in %d blks, %dK free)\n",
mi.arena>>10, mi.uordblks>>10, mi.ordblks, mi.fordblks>>10);
#endif
return 0; /* No progress made -- give up */
}
}
/*
* Just stash these values in our frame function so they won't change visibly
* during a frame. Each frame function will do this; we'll just hope that
* they don't change as the various cave-wall processes start.
*/
void specks_current_frame( struct stuff *st, struct specklist *sl )
{
st->frame_sl = sl;
st->frame_time = st->curtime;
st->frame_data = st->curdata;
st->frame_annotation = st->annotation;
specks_reupdate( st, sl );
}
#define MAXXYFAN 16
extern void specks_draw_boxes( struct stuff *st, struct AMRbox *boxes, int levelmask, Matrix Ttext, int oriented );
extern void specks_draw_mesh( struct stuff *st, struct mesh *m, int *texturing );
extern void specks_draw_ellipsoid( struct stuff *st, struct ellipsoid *e );
struct cpoint {
int rgba;
Point p;
};
void dumpcpoints( struct cpoint *cp, int n )
{
while(--n >= 0) {
glColor4ubv( (GLubyte *)&cp->rgba );
glVertex3fv( &cp->p.x[0] );
cp++;
}
}
static Point depth_fwd;
static float depth_d;
struct order {
float z;
struct speck *sp;
struct specklist *sl;
};
static int depthcmp( const void *a, const void *b )
{
return ((struct order *)a)->z < ((struct order *)b)->z ? 1
: ((struct order *)a)->z > ((struct order *)b)->z ? -1 : 0;
}
static int additive_blend;
void sortedpolys( struct stuff *st, struct specklist *slhead, Matrix *Tc2wp, float radperpix, float polysize )
{
struct speck *sp;
struct order *op, *obase;
int i, k, total, skip;
struct specklist *sl;
int usethresh = st->usethresh&P_USETHRESH ? THRESHBIT : 0;
int bps = 0;
int prevrgba = -1;
int usearea = st->polyarea;
int sizevar = st->polysizevar;
int polyorivar = st->polyorivar0;
int texturevar = st->texturevar;
int txno;
int texturing = -1;
float polyminrad = st->polymin * radperpix;
float polymaxrad = st->polymax * radperpix;
float mins2d = polyminrad * polyminrad;
int rgba;
int alpha = st->alpha * 255;
int nfan = st->npolygon<MAXXYFAN ? st->npolygon : MAXXYFAN;
float xyfan[MAXXYFAN][2];
Point sfan[MAXXYFAN];
float fanscale;
Texture *wanttx;
int additive = additive_blend;
int wantblend = additive;
int useclip = (st->clipbox.level != 0);
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
Point clipp0 = st->clipbox.p0;
Point clipp1 = st->clipbox.p1;
for(total = 0, sl = slhead; sl != NULL; sl = sl->next) {
if(sl->text != NULL || sl->nspecks == 0 || sl->special != SPECKS)
continue;
skip = st->subsample;
if(sl->subsampled != 0) /* if already subsampled */
skip /= sl->subsampled;
if(skip <= 0) skip = 1;
if(bps < sl->bytesperspeck) bps = sl->bytesperspeck;
if(usethresh) {
for(i=sl->nspecks, sp=sl->specks; i>0; i-=skip, sp=NextSpeck(sp,sl,skip)) {
if((usethresh & sp->rgba) == 0)
total++;
}
} else {
total += sl->nspecks / skip;
}
}
obase = op = (struct order *)malloc( (total+1) * sizeof(struct order) );
for(sl = slhead; sl != NULL; sl = sl->next) {
if(sl->text != NULL || sl->nspecks == 0 || sl->special != SPECKS)
continue;
skip = st->subsample;
if(sl->subsampled != 0) /* if already subsampled */
skip /= sl->subsampled;
if(skip <= 0) skip = 1;
for(i=sl->nspecks, sp=sl->specks; i > 0; i-=skip, sp=NextSpeck(sp,sl,skip)) {
float dist;
if(usethresh & sp->rgba)
continue;
dist = VDOT( &sp->p, &depth_fwd ) + depth_d;
if(dist < 0)
continue;
if(useclip &&
(sp->p.x[0] < clipp0.x[0] ||
sp->p.x[0] > clipp1.x[0] ||
sp->p.x[1] < clipp0.x[1] ||
sp->p.x[1] > clipp1.x[1] ||
sp->p.x[2] < clipp0.x[2] ||
sp->p.x[2] > clipp1.x[2]))
continue;
op->z = dist;
op->sp = sp;
op->sl = sl;
op++;
}
}
total = op - obase;
qsort( obase, total, sizeof(*obase), depthcmp );
prevrgba = 0;
/* Build prototype fan -- unit disk in screen plane */
/* Scale the fan big enough that the unit disk is inscribed in our polygon */
fanscale = 1 / (scl * cos(M_PI/nfan));
float theta = 2*M_PI*(i+0.5f)/nfan;
vcomb( &sfan[i], xyfan[i][0] * fanscale, (Point *)&Tc2w.m[0*4+0],
xyfan[i][1] * fanscale, (Point *)&Tc2w.m[1*4+0] );
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
}
if(st->usetextures == 0 || SMALLSPECKSIZE(texturevar) > bps)
texturevar = -1;
if(SMALLSPECKSIZE(polyorivar) > bps)
polyorivar = -1;
for(i = 0, op = obase; i < total; i++, op++) {
float dist, size;
sp = op->sp;
dist = op->z;
size = sp->val[sizevar] * polysize;
if(usearea) {
if(size < dist * dist * mins2d)
continue;
size = sqrtf(size);
} else {
if(size < dist * polyminrad)
continue;
}
if(size > dist * polymaxrad)
size = dist * polymaxrad;
rgba = sp->rgba & RGBBITS;
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
if(rgba != prevrgba) {
prevrgba = rgba;
rgba = RGBALPHA( prevrgba, alpha );
glColor4ubv( (GLubyte *)&rgba );
}
if(texturevar >= 0 &&
(txno = sp->val[texturevar]) >= 0 &&
txno < st->ntextures &&
(wanttx = st->textures[txno]) != NULL) {
txbind( wanttx, &texturing );
wantblend = (wanttx->flags & TXF_ADD) ? 1 : additive_blend;
} else if(texturing) {
glDisable( GL_TEXTURE_2D );
texturing = 0;
}
if(wantblend != additive) {
additive = wantblend;
glBlendFunc( GL_SRC_ALPHA, additive ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA );
}
if(polyorivar >= 0 && sp->val[polyorivar] < 9) {
float *xv = &sp->val[polyorivar];
float *yv = &sp->val[polyorivar+3];
glBegin( GL_TRIANGLE_FAN );
if(texturing) {
for(k = 0; k < nfan; k++) {
glTexCoord2fv( &xyfan[k][0] );
glVertex3f(
sp->p.x[0] + size*(xyfan[k][0]*xv[0] + xyfan[k][1]*yv[0]),
sp->p.x[1] + size*(xyfan[k][0]*xv[1] + xyfan[k][1]*yv[1]),
sp->p.x[2] + size*(xyfan[k][0]*xv[2] + xyfan[k][1]*yv[2]));
}
} else {
for(k = 0; k < nfan; k++) {
glVertex3f(
sp->p.x[0] + size*(xyfan[k][0]*xv[0] + xyfan[k][1]*yv[0]),
sp->p.x[1] + size*(xyfan[k][0]*xv[1] + xyfan[k][1]*yv[1]),
sp->p.x[2] + size*(xyfan[k][0]*xv[2] + xyfan[k][1]*yv[2]));
}
}
glEnd();
} else {
glBegin( GL_TRIANGLE_FAN );
if(texturing) {
for(k = 0; k < nfan; k++) {
glTexCoord2fv( &xyfan[k][0] );
glVertex3f(
sp->p.x[0] + size*sfan[k].x[0],
sp->p.x[1] + size*sfan[k].x[1],
sp->p.x[2] + size*sfan[k].x[2] );
}
} else {
for(k = 0; k < nfan; k++) {
glVertex3f(
sp->p.x[0] + size*sfan[k].x[0],
sp->p.x[1] + size*sfan[k].x[1],
sp->p.x[2] + size*sfan[k].x[2] );
}
}
glEnd();
}
}
free(obase);
if(texturing > 0)
txbind( NULL, NULL );
}
void drawspecks( struct stuff *st )
{
int i, slno, k;
int rgba, alpha, prevrgba = 0;
float prevsize = 0;
struct specklist *sl, *slhead;
register struct speck *p;
Matrix Tw2c, Tc2w, Ttext, Tproj, Ttemp;
static Point zero = {0,0,0};
int xywh[4];
float radperpix;
Point tp, fan[MAXXYFAN];
Point eyepoint;
Point fwd;
float fwdd;
float tscale, scl, fanscale;
int skip;
static int nxyfan = 0;
static float xyfan[MAXXYFAN][2];
static unsigned char randskip[256];
int fast = st->fast;
int inpick = st->inpick;
/*int usethresh = st->usethresh&P_USETHRESH ? THRESHBIT : 0;*/
#if USE_PTRACK
int useptrack = (getenv("PTRACK") != NULL);
#endif
float polyminrad, polymaxrad;
int useclip = (st->clipbox.level != 0);
Point clipp0 = st->clipbox.p0;
Point clipp1 = st->clipbox.p1;
float plum = st->psize;
float knee1dist2 = st->fadeknee1 * st->fadeknee1;
float knee2dist2 = st->fadeknee2 * st->fadeknee2;
float orthodist2 = st->fadeknee2 * st->fadeknee2;
float steep2knee2 = st->knee2steep * st->knee2steep / knee2dist2;
float faderball2 = 1 / (st->fadeknee2 * st->fadeknee2);
Point fadecen = st->fadecen;
enum FadeType fademodel = st->fade;
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
if(!st->useme)
return;
switch(fademodel) {
case F_CONSTANT:
if(orthodist2 <= 0)
orthodist2 = 1;
break;
case F_KNEE12:
if(st->fadeknee1 >= st->fadeknee2 || st->fadeknee1 <= 0)
fademodel = F_KNEE2; /* and fall into... */
case F_KNEE2:
if(st->fadeknee2 <= 0)
fademodel = F_SPHERICAL;
break;
case F_LREGION:
if(st->fadeknee2 <= 0) faderball2 = 1;
break;
}
{ float r=0,g=0,b=0; /* Ugh. Allow background to be non-black */
sscanf(parti_bgcolor(NULL), "%f%f%f", &r,&g,&b);
additive_blend = (r+g+b == 0);
if(st->clipbox.level > 0) {
GLdouble plane[4];
if(st->clipbox.level == 1) {
struct AMRbox b[2];
b[0] = st->clipbox;
b[0].level = 0;
b[1].level = -1;
specks_draw_boxes( st, b, ~0, Tidentity, 1 );
}
for(i = 0; i < 3; i++) {
plane[0] = plane[1] = plane[2] = 0;
plane[i] = 1;
plane[3] = -st->clipbox.p0.x[i];
glClipPlane( GL_CLIP_PLANE0 + i, plane );
glEnable( GL_CLIP_PLANE0 + i );
plane[i] = -1;
plane[3] = st->clipbox.p1.x[i];