Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
107
108
109
110
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
199
200
201
202
203
204
205
206
207
208
209
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
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
369
370
371
372
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
420
421
422
423
424
425
426
427
428
429
430
431
432
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#ifdef USE_CONSTE
#ifdef WIN32
# include "winjunk.h"
#endif
#include "futil.h"
#ifdef __APPLE__
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
#else
# include <GL/gl.h>
# include <GL/glu.h>
#endif
extern "C" {
#include "findfile.h"
};
#include "specks.h"
#include "partiviewc.h"
#include "conste.h" // declare following as extern "C"
#define CONSTE_NONE 0
#define CONSTE_LINE 1
#define CONSTE_FIG 2
struct conste
{
char name[64];
GLuint line_index; /* OpenGL display list index for line */
GLuint fig_index; /* OpenGL display list index for figure */
char line_filename[256];
char fig_filename[256];
float lnear;
float lfar;
int state;
};
struct constestuff {
conste *constes;
int num_constes;
float line_color[3];
float fig_color[3];
};
extern "C" {
void conste_init() {
static char Conste[] = "conste";
parti_add_reader( conste_read, Conste, NULL );
parti_add_commands( conste_parse_args, Conste, NULL );
}
}
int conste_build_line(conste *_cd)
{
FILE *fp;
char line[256];
char token[256];
float vec0[3],vec1[3];
if (!_cd->line_filename) return 0;
fp = fopen(_cd->line_filename,"r");
if (!fp) {
msg("Data file %s not found.",_cd->line_filename);
return 0;
}
while (fgets(line,256,fp) != NULL)
{
sscanf(line,"%s",token);
if (strcmp(token,"Lines:") == 0) {
_cd->line_index = glGenLists(1);
glNewList(_cd->line_index,GL_COMPILE_AND_EXECUTE);
glBegin(GL_LINE_STRIP);
while (fgets(line,256,fp) != NULL && line[0] != '}')
{
if (sscanf(line,"%f %f %f",&vec0[0],&vec0[1],&vec0[2]) < 3) {
glEnd();
glBegin(GL_LINE_STRIP);
} else {
glVertex3fv(vec0);
}
}
glEnd();
glEndList();
}
}
fclose(fp);
return 1;
}
int conste_build_fig(conste *_cd)
{
FILE *fp;
float pos[3];
float size,rot;
float *points;
int numPoints;
int *indexes;
int numIndexes;
int i;
if (!_cd->fig_filename) return 0;
fp = fopen(_cd->fig_filename,"rb");
if (!fp) {
msg("Data file %s not found.",_cd->fig_filename);
return 0;
}
_cd->fig_index = glGenLists(1);
glNewList(_cd->fig_index,GL_COMPILE);
fgetnf(fp, 3, pos, F_BINARY_LE);
fgetnf(fp, 1, &size, F_BINARY_LE);
fgetnf(fp, 1, &rot, F_BINARY_LE);
numPoints = -1;
fgetni(fp, 1, &numPoints, F_BINARY_LE);
if(numPoints < 0 || numPoints > 65535) {
msg("constellation file %s garbled", _cd->fig_filename);
return 0;
}
points = new float[numPoints*2];
fgetnf(fp, numPoints*2, points, F_BINARY_LE);
fgetni(fp, 1, &numIndexes, F_BINARY_LE);
indexes = new int[numIndexes];
fgetni(fp, numIndexes, indexes, F_BINARY_LE);
glPushMatrix();
/* glMultMatrixf((float *)sssim2gview);*/
glRotatef(90.0f,0.0f,0.0f,-1.0f);
glRotatef(90.0f,0.0f,-1.0f,0.0f);
if (size != 1.0f)
{
Point from,to;
from.x[0] = 0.0f;
from.x[1] = 0.0f;
from.x[2] = 1.0f;
to.x[0] = 0.5f * pos[0];
to.x[1] = 0.5f * pos[1];
to.x[2] = 0.5f * pos[2];
float cpdist = sqrtf(to.x[0]*to.x[0]+to.x[1]*to.x[1]+to.x[2]*to.x[2]);
to.x[0] /= cpdist;
to.x[1] /= cpdist;
to.x[2] /= cpdist;
glTranslatef(to.x[0],to.x[1],to.x[2]);
Matrix mat;
grotation(&mat,&from,&to);
glMultMatrixf(mat.m);
glScalef(size/cpdist,size/cpdist,1.0);
glRotatef(rot,0.0f,0.0f,1.0f);
}
glBegin(GL_LINE_STRIP);
for (i=0;i<numIndexes;i++)
{
if (indexes[i] >= 0) {
glVertex2f(-points[indexes[i]*2],points[indexes[i]*2+1]);
} else {
glEnd();
glBegin(GL_LINE_STRIP);
}
}
glEnd();
glPopMatrix();
delete [] points;
delete [] indexes;
glEndList();
fclose(fp);
return 1;
}
int conste_read_data(conste *_cd,char *_filename)
{
FILE *fp;
char line[256];
char *filename;
char token[256];
char *start;
float x,y,z;
float vec[3],center[3];
float lnear,lfar,dist;
lnear = 0.0f;
lfar = 0.0f;
dist = 0.0f;
_cd->line_index = 0;
_cd->fig_index = 0;
_cd->state = CONSTE_LINE | CONSTE_FIG;
strcpy(_cd->line_filename,_filename);
fp = fopen(_filename,"r");
if (!fp) {
msg("Data file %s not found.",_filename);
return 0;
}
while (fgets(line,256,fp) != NULL)
{
sscanf(line,"%s",token);
if (strcmp(token,"Name:") == 0) {
line[strlen(line)-1] = '\0';
start = &line[strlen("Name:")];
while (*start == ' ') start++;
strcpy(_cd->name,start);
}
else if (strcmp(token,"Art:") == 0) {
sscanf(line,"%*s %s",_cd->fig_filename);
filename = findfile(_filename,_cd->fig_filename);
if (filename)
strcpy(_cd->fig_filename,filename);
}
else if (strcmp(token,"Lines:") == 0) {
while (fgets(line,256,fp) != NULL && line[0] != '}')
{
if (sscanf(line,"%f %f %f",&x,&y,&z) == 3) {
dist = x*x+y*y+z*z;
if (lnear == 0.0f || dist < lnear) lnear = dist;
if (lfar == 0.0f || dist > lfar) lfar = dist;
}
}
}
}
_cd->lnear = sqrtf(lnear);
_cd->lfar = sqrtf(lfar);
fclose(fp);
return 1;
}
int conste_read(struct stuff **_stp, int argc, char *argv[], char *_filename, void * )
{
FILE *fp;
char data_filename[256];
char *filename;
int i;
struct stuff *_st = *_stp;
if(0!=strcmp(argv[0], "conste"))
return 0;
if(argc!=2) {
msg("conste: expected \"conste <file-containing-list-of-filenames>\"");
return 0;
}
fp = fopen(argv[1],"r");
if (!fp) {
msg("conste %s: data file not found.", argv[1]);
return 0;
}
constestuff *cs = new constestuff;
fscanf(fp,"%i",&cs->num_constes);
cs->constes = new conste[cs->num_constes];
for (i=0;i<cs->num_constes;i++) {
fscanf(fp,"%s",data_filename);
filename = findfile(_filename,data_filename);
if (filename)
conste_read_data(&cs->constes[i],filename);
}
cs->line_color[0] = 0.400000f;
cs->line_color[1] = 0.400000f;
cs->line_color[2] = 0.800000f;
cs->fig_color[0] = 0.500000f;
cs->fig_color[1] = 0.500000f;
cs->fig_color[2] = 0.500000f;
_st->conste = 1;
_st->constedata = cs;
_st->textsize = 1.0f;
fclose(fp);
return 1;
}
void conste_draw(struct stuff *_st)
{
int i;
glPushMatrix();
glRotatef(90.0f,0.0f,0.0f,1.0f);
glRotatef(90.0f,1.0f,0.0f,0.0f);
constestuff *cs = (constestuff *)_st->constedata;
if (_st->usepoly)
{
glColor3fv(cs->line_color);
for (i=0;i<cs->num_constes;i++) {
if (cs->constes[i].state & CONSTE_LINE) {
if (cs->constes[i].line_index == 0)
conste_build_line(&cs->constes[i]);
glCallList(cs->constes[i].line_index);
}
}
}
if (_st->usetextures)
{
glColor3fv(cs->fig_color);
for (i=0;i<cs->num_constes;i++) {
if (cs->constes[i].state & CONSTE_FIG) {
if (cs->constes[i].fig_index == 0)
conste_build_fig(&cs->constes[i]);
glPushMatrix();
glScalef((cs->constes[i].lnear + cs->constes[i].lfar) / 2.0f,
(cs->constes[i].lnear + cs->constes[i].lfar) / 2.0f,
(cs->constes[i].lnear + cs->constes[i].lfar) / 2.0f);
glCallList(cs->constes[i].fig_index);
glPopMatrix();
}
}
}
glPopMatrix();
}
int conste_parse_args(struct stuff **_stp,int _argc,char *_argv[], char *_filename, void *)
{
char result[1024];
int interest = 0;
int i,j;
struct stuff *_st = *_stp;
if(_argc < 1 || 0!=strncmp(_argv[0], "conste", 3))
return 0;
constestuff *cs = (constestuff *)_st->constedata;
if (_argc > 1) {
if (!strcmp(_argv[0],"line") || !strcmp(_argv[0],"lines"))
interest = CONSTE_LINE;
else if (!strcmp(_argv[0],"fig") || !strcmp(_argv[0],"figs") ||
!strcmp(_argv[0],"figure") || !strcmp(_argv[0],"figures"))
interest = CONSTE_FIG;
else {
msg("conste {line|fig} {show|hide} [constname...|all] -or- {line|fig} color [R G B]");
return 1;
}
if (!strcmp(_argv[1],"show")) {
if (interest == CONSTE_LINE)
strcpy(result,"show constellation lines : ");
else
strcpy(result,"show constellation figures : ");
for (j=2;j<_argc;j++) {
if (!strcmp(_argv[j],"all")) {
for (i=0;i<cs->num_constes;i++)
if (!(cs->constes[i].state & interest))
cs->constes[i].state += interest;
break;
} else {
for (i=0;i<cs->num_constes;i++)
if (!strncmp(_argv[j],cs->constes[i].name,strlen(_argv[j])))
if (!(cs->constes[i].state & interest)) {
cs->constes[i].state += interest;
strcat(result,cs->constes[i].name);
strcat(result," ");
}
}
}
msg(result);
}
else if (!strcmp(_argv[1],"hide")) {
if (interest == CONSTE_LINE)
strcpy(result,"hide constellation lines : ");
else
strcpy(result,"hide constellation figures : ");
for (j=2;j<_argc;j++) {
if (!strcmp(_argv[j],"all")) {
for (i=0;i<cs->num_constes;i++)
if (cs->constes[i].state & interest)
cs->constes[i].state -= interest;
strcat(result,"all ");
break;
} else {
for (i=0;i<cs->num_constes;i++)
if (!strncmp(_argv[j],cs->constes[i].name,strlen(_argv[j])))
if (cs->constes[i].state & interest) {
cs->constes[i].state -= interest;
strcat(result,cs->constes[i].name);
strcat(result," ");
}
}
}
msg(result);
}
else if (!strcmp(_argv[1],"color")) {
if (interest == CONSTE_LINE) {
if (_argc >= 4) {
cs->line_color[0] = atof(_argv[2]);
cs->line_color[1] = atof(_argv[3]);
cs->line_color[2] = atof(_argv[4]);
}
msg("lines color %.3f %.3f %.3f (RGB constellation line color)",
cs->fig_color[0],cs->fig_color[1],cs->fig_color[2]);
} else {
if (_argc >= 4) {
cs->fig_color[0] = atof(_argv[2]);
cs->fig_color[1] = atof(_argv[3]);
cs->fig_color[2] = atof(_argv[4]);
}
msg("figures color %.3f %.3f %.3f (RGB constellation figure color)",
cs->fig_color[0],cs->fig_color[1],cs->fig_color[2]);
}
}
}
return 1;
}
#endif /* USE_CONSTE */