Debian Codegraph @

debian/external_deps/fetk/sg/tools/main.c

raw
1 /*
2 * ***************************************************************************
3 * SG = < Socket Graphics >
4 * Copyright (C) 1994-- Michael Holst
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * rcsid="$Id: main.c,v 1.32 2010/08/09 19:02:07 fetk Exp $"
21 * ***************************************************************************
22 */
23
24 /*
25 * ***************************************************************************
26 * File: main.c
27 *
28 * Purpose: Driver for [ X11/GLX | Win32/glW | etc ]-based display tool SG.
29 *
30 * Notes: SG is a visualization tool somewhat similar to Geomview
31 * (a tool developed by University of Minnesota's Geometry Center).
32 * SG code can display Geomview "OFF" files, as well as SGI's
33 * OpenInventor IV files, and several other graphics file formats,
34 * including a new format called BH (Bank/Holst) graphics format.
35 *
36 * SG uses files, UNIX domain sockets, and INET sockets
37 * to accept ASCII or XDR (RPC's eXternal Data Format) input from
38 * a polygon-generating code such as a finite element code.
39 *
40 * You start SG with appropriate parameters to tell it to read
41 * geometry and control data from a particular UNIX or INET socket,
42 * rather than from a normal data file or from the standard input.
43 * We use a parameter syntax which is similar to Geomview; for
44 * example, if you start up SG as follows:
45 *
46 * ./mcsg -Mcs 1
47 *
48 * then SG will "listen" for input on the UNIX domain socket
49 * /geomview/1-username, the location of which again is to be
50 * compatible with applications that are designed to function
51 * with Geomview.
52 *
53 * SG can work with internet (INET) sockets in addition to UNIX
54 * domain sockets, which Geomview can't do. In particular, SG
55 * can be run on an SGI Octane, and you can run your polygon
56 * generating finite element code on an Origin or an Alpha/Linux
57 * box. You then just send the geometry over network sockets to
58 * the waiting SG. It has the appearance of working just like a
59 * local UNIX domain socket implementation. Note that this is *not*
60 * the same as displaying an X window from an alpha box remotely on
61 * an SGI; this is extremely fast. For example, to start up SG
62 * to listen for XDR data on INET socket 1+14916 (all socket numbers
63 * in SG are relative to the safe socket offset number 14916),
64 * you would type the following:
65 *
66 * ./mcsg -xdr -Mci 1
67 *
68 * Any machine on the internet that writes to socket 1+14916 on
69 * the machine which is running this invocation of SG will
70 * reach SG waiting for input in XDR format.
71 *
72 * SG has one additional advantage (although some would call it
73 * a disadvantage), in that it also runs under Windows NT. The
74 * NT version also supports the network socket use via WINSOCK;
75 * you can crunch on your Alpha/Linux box, and display realtime
76 * through internet sockets on your NT/OpenGL box using your
77 * Diamond FireGL board, for example.
78 *
79 * If the SG binary is named anything other than "mcsg", then
80 * it attempts to configure itself using a somewhat more
81 * sophisticated window frame containing buttons for setting
82 * the various controlling parameters as an alternative to
83 * providing them at the command line. This allows for an SG
84 * instance to be e.g. reconfigured at run-time to take input
85 * from a different socket or socket type, or to toggle between
86 * ASCII and XDR input. You can also toggle between the two
87 * modes (buttons or no buttons) by pressing the "m" key.
88 * The various keys which affect the behavior of sg and mcsg
89 * are listed in a small menu printed to standard out if you
90 * pres the "?" key at run-time.
91 *
92 * Author: Michael Holst
93 * ***************************************************************************
94 */
95
96 #include <sg/vgl.h>
97
98 #define VEMBED(rctag) VPRIVATE const char* rctag; \
99 static void* use_rcsid=(0 ? &use_rcsid : (void*)&rcsid);
100 VEMBED(rcsid="$Id: main.c,v 1.32 2010/08/09 19:02:07 fetk Exp $")
101
102 typedef struct Vertx {
103 float x[3]; /* (x,y,z) coordinate of a vertex */
104 float c[4]; /* (r,g,b,a) coloring for this vertex */
105 float r; /* radius of sphere at this vertex (0.0=point) */
106 } Vertx;
107
108 #define VMAXPGV 15 /* maximum number of vertices in a planer polygon */
109 typedef struct Polyg {
110 int numPV; /* num vertices in poly ( 3 <= numV <= VMAXPGV ) */
111 int v[VMAXPGV]; /* vertex numbers of this polygon */
112 float c[4]; /* (r,g,b,a) coloring for this polygon */
113 } Polyg;
114
115 /* max allowed garbage tokens before recognizing something useful */
116 VPRIVATE int tokMaxHEAD=40;
117 VPRIVATE int tokMaxBODY=1000;
118
119 /* the Inventor comment char set and white space char set */
120 VPUBLIC char *INVwhiteChars = " ,\t\n";
121 VPUBLIC char *INVcommChars = "#";
122
123 /* the OFF comment char set and white space char set */
124 VPUBLIC char *OFFwhiteChars = " \t\n";
125 VPUBLIC char *OFFcommChars = "#";
126
127 /* the PDB comment char set and white space char set */
128 VPUBLIC char *PDBwhiteChars = " \t\n";
129 VPUBLIC char *PDBcommChars = "#";
130
131 /* the BH comment char set and white space char set */
132 VPUBLIC char *BHwhiteChars = " \t\n";
133 VPUBLIC char *BHcommChars = "#";
134
135 /* global variables */
136 VPRIVATE char PR[80];
137 VPRIVATE float frame_xscale = 1.0;
138 VPRIVATE float frame_yscale = 1.0;
139 VPRIVATE float frame_zscale = 1.0;
140 VPRIVATE float frame_xshift = 0.0;
141 VPRIVATE float frame_yshift = 0.0;
142 VPRIVATE float frame_zshift = 0.0;
143
144 VPRIVATE char *theBuffer = VNULL;
145 VPRIVATE int theBufferSize = 0;
146
147 /*
148 * ***************************************************************************
149 * Frame codes:
150 *
151 * ._____._____._____. ._____._____._____. ._____._____.......
152 * | | | | | | | .
153 * | | | | 2 | | | .
154 * | 1 | | 4 |_____| | ? |......
155 * | | | | | | | .
156 * | | | | 3 | | | .
157 * |_____._____._____| |_____._____|_____| |_____._____.......
158 *
159 * Display list codes:
160 *
161 * List Frame Type
162 *
163 * 0 1 non-rotating, non-lighted
164 * 1 1 non-rotating, non-lighted
165 * 2 2 non-rotating, non-lighted
166 * 3 3 non-rotating, non-lighted
167 *
168 * 4 4 non-rotating, non-lighted
169 * 5 4 rotating, non-lighted
170 * 6 4 rotating, non-lighted
171 * 7 4 rotating, lighted
172 * 8 4 rotating, lighted
173 * 9 4 non-rotating, lighted
174 *
175 * ***************************************************************************
176 */
177
178 /*
179 * ***************************************************************************
180 * Purpose: Frame transformation selection
181 *
182 * Author: Michael Holst
183 * ***************************************************************************
184 */
185 VPUBLIC void frame(int listNumber)
186 {
187 if (listNumber == 2) {
188 frame_xscale = 0.5;
189 frame_yscale = 0.5;
190 frame_zscale = 0.0;
191 frame_xshift = 1.0;
192 frame_yshift = 0.5;
193 frame_zshift = 0.8;
194 } else if (listNumber == 3) {
195 frame_xscale = 0.5;
196 frame_yscale = 0.5;
197 frame_zscale = 0.0;
198 frame_xshift = 1.0;
199 frame_yshift = 0.0;
200 frame_zshift = 0.8;
201 } else {
202 frame_xscale = 1.0;
203 frame_yscale = 1.0;
204 frame_zscale = 1.0;
205 frame_xshift = 0.0;
206 frame_yshift = 0.0;
207 frame_zshift = 0.0;
208 }
209 }
210
211 /*
212 * ***************************************************************************
213 * Purpose: Apply the frame transformation
214 *
215 * Author: Michael Holst
216 * ***************************************************************************
217 */
218 VPUBLIC void frameTransform(int numPV, float *x, float *y, float *z)
219 {
220 int i;
221
222 for (i=0; i<numPV; i++) {
223 x[i] = frame_xscale * x[i] + frame_xshift;
224 y[i] = frame_yscale * y[i] + frame_yshift;
225 z[i] = frame_zscale * z[i] + frame_zshift;
226 }
227 for (i=0; i<numPV; i++) {
228 x[i] = 2.0 * x[i] - 1.0;
229 y[i] = 2.0 * y[i] - 1.0;
230 z[i] = 2.0 * z[i] - 1.0;
231 }
232 }
233
234 /*
235 * ***************************************************************************
236 * Purpose: Apply the inverse frame transformation
237 *
238 * Author: Michael Holst
239 * ***************************************************************************
240 */
241 VPUBLIC void frameTransformInverse(int numPV, float *x, float *y, float *z)
242 {
243 int i;
244
245 for (i=0; i<numPV; i++) {
246 x[i] = (x[i] - frame_xshift) / frame_xscale;
247 y[i] = (y[i] - frame_yshift) / frame_yscale;
248 z[i] = (z[i] - frame_zshift) / frame_zscale;
249 }
250 for (i=0; i<numPV; i++) {
251 x[i] = (x[i] + 1.0) / 2.0;
252 y[i] = (y[i] + 1.0) / 2.0;
253 z[i] = (z[i] + 1.0) / 2.0;
254 }
255 }
256
257 /*
258 * ***************************************************************************
259 * Purpose: Transform poly data to BH data
260 *
261 * Author: Michael Holst
262 * ***************************************************************************
263 */
264 VPRIVATE int poly2bh(Vgl *thee,
265 int numV, int numP, Vertx *vert, Polyg *poly)
266 {
267 int i, j, p, numPV;
268 float c[4], r, Min, Max, Len, SC, min[3], max[3];
269 float x[VMAXPGV+1], y[VMAXPGV+1], z[VMAXPGV+1];
270
271 /* sanity check */
272 VJMPERR1( numV > 0 );
273 VJMPERR1( numP >= 0 );
274
275 /* create internal XDR buffer */
276 VASSERT( VNULL != (thee->pbuf=Vio_ctor("BUFF","XDR","localhost","0","w")));
277 Vio_setWhiteChars(thee->pbuf, BHwhiteChars);
278 Vio_setCommChars(thee->pbuf, BHcommChars);
279 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s\n","bhsingle") );
280
281 /* collect bounding box info */
282 min[0] = VLARGE;
283 max[0] = -VLARGE;
284 min[1] = VLARGE;
285 max[1] = -VLARGE;
286 min[2] = VLARGE;
287 max[2] = -VLARGE;
288 for (j=0; j<numV; j++) {
289 for (p=0; p<3; p++) {
290 if (vert[j].x[p] < min[p]) min[p] = vert[j].x[p];
291 if (vert[j].x[p] > max[p]) max[p] = vert[j].x[p];
292 }
293 }
294
295 /* the common cube dmensions */
296 Min = VLARGE; Max = -VLARGE;
297 if (min[0] < Min) Min = min[0];
298 if (max[0] > Max) Max = max[0];
299 if (min[1] < Min) Min = min[1];
300 if (max[1] > Max) Max = max[1];
301 if (min[2] < Min) Min = min[2];
302 if (max[2] > Max) Max = max[2];
303 Len = VABS(Max - Min);
304 if (Len == 0) SC = 1.0;
305 else SC = 1.0 / Len;
306
307 /* apply affine transformation to take all verts to master cube */
308 for (i=0; i<numV; i++) {
309 vert[i].x[0] = SC * (2.0*vert[i].x[0] - min[0] - max[0]);
310 vert[i].x[1] = SC * (2.0*vert[i].x[1] - min[1] - max[1]);
311 vert[i].x[2] = SC * (2.0*vert[i].x[2] - min[2] - max[2]);
312 }
313
314 /* initialize things */
315 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","putl",0) );
316
317 /* vertices/polygons */
318 if (numP > 0) {
319
320 /* polygons (display lists 7,8: rotated, lighted) */
321 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","list",7) );
322 frame(7);
323 for (i=0; i<numP; i++) {
324 numPV = poly[i].numPV;
325 for (j=0; j<numPV; j++) {
326 x[j] = vert[ poly[i].v[j] ].x[0];
327 y[j] = vert[ poly[i].v[j] ].x[1];
328 z[j] = vert[ poly[i].v[j] ].x[2];
329 }
330 for (j=0; j<4; j++) c[j] = poly[i].c[j];
331 frameTransformInverse(numPV,x,y,z);
332 VJMPERR2( 0 < Vio_printf(thee->pbuf,
333 "%s %e %e %e %d\n", "fill",c[0],c[1],c[2],numPV) );
334 for (j=0; j<numPV; j++) {
335 VJMPERR2( 0 < Vio_printf(thee->pbuf," %e",x[j]) );
336 }
337 VJMPERR2( 0 <= Vio_printf(thee->pbuf,"\n") );
338 for (j=0; j<numPV; j++) {
339 VJMPERR2( 0 < Vio_printf(thee->pbuf," %e",y[j]) );
340 }
341 VJMPERR2( 0 <= Vio_printf(thee->pbuf,"\n") );
342 for (j=0; j<numPV; j++) {
343 VJMPERR2( 0 < Vio_printf(thee->pbuf," %e",z[j]) );
344 }
345 VJMPERR2( 0 <= Vio_printf(thee->pbuf,"\n") );
346 }
347 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","list",-7) );
348
349 /* edges (display lists 5,6: rotated, non-lighted */
350 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","list",5) );
351 frame(5);
352 for (i=0; i<4; i++) c[i] = 0.0;
353 for (i=0; i<numP; i++) {
354 numPV = poly[i].numPV;
355 for (j=0; j<numPV; j++) {
356 x[j] = vert[ poly[i].v[j] ].x[0];
357 y[j] = vert[ poly[i].v[j] ].x[1];
358 z[j] = vert[ poly[i].v[j] ].x[2];
359 }
360 x[numPV] = vert[ poly[i].v[0] ].x[0];
361 y[numPV] = vert[ poly[i].v[0] ].x[1];
362 z[numPV] = vert[ poly[i].v[0] ].x[2];
363 frameTransformInverse(numPV+1,x,y,z);
364 VJMPERR2( 0 < Vio_printf(thee->pbuf,
365 "%s %e %e %e %d\n", "line",c[0],c[1],c[2],numPV+1) );
366 for (j=0; j<numPV+1; j++) {
367 VJMPERR2( 0 < Vio_printf(thee->pbuf," %e",x[j]) );
368 }
369 VJMPERR2( 0 <= Vio_printf(thee->pbuf,"\n") );
370 for (j=0; j<numPV+1; j++) {
371 VJMPERR2( 0 < Vio_printf(thee->pbuf," %e",y[j]) );
372 }
373 VJMPERR2( 0 <= Vio_printf(thee->pbuf,"\n") );
374 for (j=0; j<numPV+1; j++) {
375 VJMPERR2( 0 < Vio_printf(thee->pbuf," %e",z[j]) );
376 }
377 VJMPERR2( 0 <= Vio_printf(thee->pbuf,"\n") );
378 }
379 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","list",-5) );
380
381 /* vertices only (for placing spheres at points) */
382 } else {
383
384 /* everything here is a point */
385 numPV = 1;
386
387 /* spheres (display lists 7,8: rotated, lighted) */
388 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","list",8) );
389 frame(7);
390 for (i=0; i<numV; i++) {
391 r = vert[i].r;
392 x[0] = vert[i].x[0];
393 y[0] = vert[i].x[1];
394 z[0] = vert[i].x[2];
395 frameTransformInverse(1,x,y,z);
396 for (j=0; j<4; j++) c[j] = vert[i].c[j];
397 VJMPERR2( 0 < Vio_printf(thee->pbuf,
398 "%s %e %e %e %e %e %e %e\n",
399 "pont",c[0],c[1],c[2],SC*r,x[0],y[0],z[0]) );
400 }
401 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","list",-8) );
402 }
403
404 /* finish up */
405 VJMPERR2( 0 < Vio_printf(thee->pbuf,"%s %d\n","putl",-1) );
406
407 /* return with no errors (with polygons) */
408 theBufferSize = Vio_bufSize(thee->pbuf);
409 theBuffer = Vio_bufGive(thee->pbuf);
410 Vio_dtor( &(thee->pbuf) );
411 return 1;
412
413 VERROR1:
414 fprintf(stderr,"poly2bh: problem with input data\n");
415 theBufferSize = 0;
416 theBuffer = VNULL;
417 Vio_dtor( &(thee->pbuf) );
418 return 0;
419
420 VERROR2:
421 fprintf(stderr,"poly2bh: problem with output data\n");
422 theBufferSize = 0;
423 theBuffer = VNULL;
424 Vio_dtor( &(thee->pbuf) );
425 return 0;
426 }
427
428 /*
429 * ***************************************************************************
430 * Purpose: Render BH data to a GL device
431 *
432 * Author: Michael Holst
433 * ***************************************************************************
434 */
435 VPRIVATE int bh2gl(Vgl *thee)
436 {
437 int j, ncolor, myColor, done, numPV, ikey, numF, numL, numP;
438 int listNumber, listNumberTmp;
439 char tok[VMAX_BUFSIZE];
440 float c[4], x[VMAX_BUFSIZE], y[VMAX_BUFSIZE], z[VMAX_BUFSIZE];
441 float red[VMAX_BUFSIZE], green[VMAX_BUFSIZE], blue[VMAX_BUFSIZE];
442 float fval, radius;
443
444 /* some i/o */
445 numF = 0;
446 numL = 0;
447 numP = 0;
448 fprintf(stderr,"%s: Rendering BH data as GL..", PR);
449
450 /* create internal XDR buffer */
451 VASSERT( VNULL != (thee->pbuf=Vio_ctor("BUFF","XDR","localhost","0","r")));
452 Vio_setWhiteChars(thee->pbuf, BHwhiteChars);
453 Vio_setCommChars(thee->pbuf, BHcommChars);
454 Vio_bufTake(thee->pbuf, theBuffer, theBufferSize);
455
456 /* initialization */
457 listNumber = -1;
458
459 /* this better be a "bhsingle" file */
460 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%s",tok) );
461 VJMPERR1( strstr(tok,"bhsingle") != VNULL );
462
463 /* the first command should be putl */
464 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%s",tok) );
465 VJMPERR1( strstr(tok,"putl") != VNULL );
466
467 /* number of colors (and possible RGB arrays) */
468 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&ncolor) );
469 VJMPERR1( ncolor >= 0 );
470 if (ncolor == 0) {
471 /* non-color indexed mode */
472 } else if (ncolor > 0) {
473 for (j=0; j<ncolor; j++) {
474 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
475 red[j] = fval;
476 }
477 for (j=0; j<ncolor; j++) {
478 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
479 green[j] = fval;
480 }
481 for (j=0; j<ncolor; j++) {
482 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
483 blue[j] = fval;
484 }
485 } else { VJMPERR1(0); }
486
487 /* initialize things; make us current OpenGL device */
488 Vgl_putl( thee, ncolor, red, green, blue );
489
490 /* process commands until "putl" is encountered again */
491 done = 0;
492 while (!done) {
493
494 /* get and process the next command token */
495 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%s",tok) );
496
497 /* CASE: display list begin/end */
498 if ( strstr(tok,"list") != VNULL ) {
499
500 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&listNumberTmp) );
501 if ( listNumberTmp >= 0 ) {
502 VJMPERR1( listNumber < 0 );
503 listNumber = listNumberTmp;
504 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
505 frame(listNumber);
506 Vgl_list(thee,listNumber,1);
507 } else {
508 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
509 VJMPERR1( listNumberTmp == -listNumber );
510 listNumber = -1;
511 frame(listNumber);
512 Vgl_list(thee,listNumber,1);
513 }
514
515 /* CASE: line */
516 } else if ( strstr(tok,"line") != VNULL ) {
517
518 numL++;
519
520 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
521 if (ncolor == 0) {
522 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
523 c[0] = fval;
524 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
525 c[1] = fval;
526 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
527 c[2] = fval;
528 } else { /* (ncolor > 0) */
529 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&myColor) );
530 c[0] = red[ myColor - 1 ];
531 c[1] = green[ myColor - 1 ];
532 c[2] = blue[ myColor - 1 ];
533 }
534 c[3] = 0.0;
535 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&numPV) );
536 for (j=0; j<numPV; j++) {
537 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
538 x[j] = fval;
539 }
540 for (j=0; j<numPV; j++) {
541 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
542 y[j] = fval;
543 }
544 for (j=0; j<numPV; j++) {
545 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
546 z[j] = fval;
547 }
548 frameTransform(numPV,x,y,z);
549 Vgl_line(thee,x,y,z,numPV,-1,c);
550
551 /* CASE: fill */
552 } else if ( strstr(tok,"fill") != VNULL ) {
553
554 numF++;
555
556 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
557 if (ncolor == 0) {
558 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
559 c[0] = fval;
560 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
561 c[1] = fval;
562 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
563 c[2] = fval;
564 } else { /* (ncolor > 0) */
565 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&myColor) );
566 c[0] = red[ myColor - 1 ];
567 c[1] = green[ myColor - 1 ];
568 c[2] = blue[ myColor - 1 ];
569 }
570 c[3] = 0.0;
571 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&numPV) );
572 for (j=0; j<numPV; j++) {
573 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
574 x[j] = fval;
575 }
576 for (j=0; j<numPV; j++) {
577 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
578 y[j] = fval;
579 }
580 for (j=0; j<numPV; j++) {
581 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
582 z[j] = fval;
583 }
584 frameTransform(numPV,x,y,z);
585 Vgl_fill(thee,x,y,z,numPV,-1,c);
586
587 /* CASE: pont */
588 } else if ( strstr(tok,"pont") != VNULL ) {
589
590 numP++;
591
592 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
593 if (ncolor == 0) {
594 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
595 c[0] = fval;
596 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
597 c[1] = fval;
598 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
599 c[2] = fval;
600 } else { /* (ncolor > 0) */
601 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&myColor) );
602 c[0] = red[ myColor - 1 ];
603 c[1] = green[ myColor - 1 ];
604 c[2] = blue[ myColor - 1 ];
605 }
606 c[3] = 0.0;
607 numPV = 1;
608 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
609 radius = fval;
610 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
611 x[0] = fval;
612 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
613 y[0] = fval;
614 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%e",&fval) );
615 z[0] = fval;
616 frameTransform(numPV,x,y,z);
617 Vgl_pont(thee,x,y,z,numPV,-1,c,2,radius);
618
619 /* CASE: putl */
620 } else if ( strstr(tok,"putl") != VNULL ) {
621
622 VJMPERR1( listNumber < 0 );
623 VJMPERR1( 1==Vio_scanf(thee->pbuf,"%d",&ikey) );
624 VJMPERR1( ikey == -1 );
625 done = 1;
626 Vgl_putl( thee, -1, VNULL, VNULL, VNULL );
627
628 } else { VJMPERR1(0); }
629 }
630
631 /* return with no errors */
632 fprintf(stderr,"..%d fills, %d lines, %d points.\n", numF, numL, numP);
633 return 1;
634
635 VERROR1:
636 fprintf(stderr,"bh2gl: problem reading BH data.\n");
637 return 0;
638 }
639
640 /*
641 * ***************************************************************************
642 * Purpose: Read a BH-file (Bank/Holst compressed graphics format)
643 *
644 * Notes: Each "BH" file begins with either "bhsingle" or "bhdouble".
645 * The "bhsingle" and "bhdouble" are necessary for XDR encoding.
646 * If "bhdouble" is used then the XDR encoding uses "double"
647 * in place of "float" for all floating point numbers above.
648 *
649 * Other than the "bhsingle" or "bhdouble" keywords, there are
650 * only 5 primatives in the BH language:
651 *
652 * PUTL:
653 * putl <ncolors> ==> begin/end a plot
654 * ncolors < 0 : end a plot
655 * ncolors >= 0 : begin a plot
656 * ncolors = 0 : begin a plot (direct)
657 * ncolors > 0 : begin a plot (indexed)
658 *
659 * LIST:
660 * list <nlist> ==> begin/end a display list
661 * list > 0 : begin list <nlist>
662 * list < 0 : end list <nlist>
663 *
664 * FILL:
665 * fill <R> <G> <B> <nvert> ==> draw a filled colored polygon
666 * <R> : "red" float between 0 and 1
667 * <G> : "green" float between 0 and 1
668 * <B> : "blue" float between 0 and 1
669 * <nvert> : number of vertices in polygon
670 * (or)
671 * fill <cindex> <nvert> ==> draw a filled polygon
672 * <cindex> : index into color array
673 * <nvert> : number of vertices in polygon
674 * (followed by:)
675 * x_vert_0 y_vert_0 z_vert_0
676 * ...
677 * x_vert_{<nvert>-1} y_vert_{<nvert>-1} z_vert_{<nvert>-1}
678 *
679 * LINE:
680 * line <R> <G> <B> <nvert> ==> draw a colored line
681 * <R> : "red" float between 0 and 1
682 * <G> : "green" float between 0 and 1
683 * <B> : "blue" float between 0 and 1
684 * <nvert> : number of vertices in polygon
685 * (or)
686 * line <cindex> <nvert> ==> draw a colored line
687 * <cindex> : index into color array
688 * <nvert> : number of vertices in polygon
689 * (followed by:)
690 * x_vert_0 y_vert_0 z_vert_0
691 * ...
692 * x_vert_{<nvert>-1} y_vert_{<nvert>-1} z_vert_{<nvert>-1}
693 *
694 * PONT:
695 * pont <R> <G> <B> <radius> <x> <y> <z> ==> draw a sphere
696 * <R> : "red" float between 0 and 1
697 * <G> : "green" float between 0 and 1
698 * <B> : "blue" float between 0 and 1
699 * <radius> : radius of the sphere
700 * <x> : x-coordinate of sphere center
701 * <y> : y-coordinate of sphere center
702 * <z> : z-coordinate of sphere center
703 * (or)
704 * pont <cindex> <radius> <x> <y> <z> ==> draw a sphere
705 * <cindex> : index into color array
706 * <radius> : radius of the sphere
707 * <x> : x-coordinate of sphere center
708 * <y> : y-coordinate of sphere center
709 * <z> : z-coordinate of sphere center
710 *
711 * DIRECT method: color given as RGB with each object (fill or line)
712 *
713 * ###################################################################
714 * bhsingle # filetype key (bhsingle or bhdouble)
715 * putl 0 # begin plot (RGB colors given with each object)
716 * list 7 # start display list 7 (of 9 posible)
717 * fill 1.0 0.0 0.0 3 # fill polygon with 3 vertices, RGB=(1.0,0.0,0.0)
718 * 0.0 0.0 0.0 # vertex 0 (x-y-z coords)
719 * 1.0 0.0 0.0 # vertex 1 (x-y-z coords)
720 * 0.0 1.0 0.0 # vertex 2 (x-y-z coords)
721 * list -7 # end display list 7
722 * list 5 # start display list 5 (of 9 posible)
723 * line 1.0 1.0 1.0 4 # line connecting 4 vertices, RGB=(1.0,1.0,1.0)
724 * 0.0 0.0 0.0 # vertex 0 (x-y-z coords)
725 * 1.0 0.0 0.0 # vertex 1 (x-y-z coords)
726 * 0.0 1.0 0.0 # vertex 2 (x-y-z coords)
727 * 0.0 0.0 1.0 # vertex 3 (x-y-z coords)
728 * list -5 # end display list 5
729 * putl -1 # end plot
730 * ###################################################################
731 *
732 * INDEXED method: color given as RGB index with each object (fill or line)
733 *
734 * ###################################################################
735 * bhsingle # filetype key (bhsingle or bhdouble)
736 * putl 2 # begin plot (num colors, followed by RGB array)
737 * 1.0 1.0 1.0 # color 0 (black)
738 * 1.0 0.0 0.0 # color 1 (red)
739 * list 7 # start display list 7 (of 9 posible)
740 * fill 1 3 # fill polygon with 3 vertices, RGB=color 1
741 * 0.0 0.0 0.0 # vertex 0 (x-y-z coords)
742 * 1.0 0.0 0.0 # vertex 1 (x-y-z coords)
743 * 0.0 1.0 0.0 # vertex 2 (x-y-z coords)
744 * list -7 # end display list 7
745 * list 5 # start display list 5 (of 9 posible)
746 * line 0 4 # line connecting 4 vertices, RGB=color 0
747 * 0.0 0.0 0.0 # vertex 0 (x-y-z coords)
748 * 1.0 0.0 0.0 # vertex 1 (x-y-z coords)
749 * 0.0 1.0 0.0 # vertex 2 (x-y-z coords)
750 * 0.0 0.0 1.0 # vertex 3 (x-y-z coords)
751 * list -5 # end display list 5
752 * putl -1 # end plot
753 * ###################################################################
754 *
755 * Author: Michael Holst
756 * ***************************************************************************
757 */
758 VPRIVATE int getBH(Vgl *thee, int *numF, int *numL, int dubl)
759 {
760 int j, ncolor, myColor, done, numPV, ikey;
761 int listNumber, listNumberTmp;
762 char tok[VMAX_BUFSIZE];
763 float c[4], x[VMAX_BUFSIZE], y[VMAX_BUFSIZE], z[VMAX_BUFSIZE];
764 float red[VMAX_BUFSIZE], green[VMAX_BUFSIZE], blue[VMAX_BUFSIZE];
765 float fval;
766 double dval;
767
768 /* we can do ASC or XDR */
769 VJMPERR2( (thee->sock->frmt == VIO_ASC) || (thee->sock->frmt == VIO_XDR) );
770
771 /* set the comment/whitespace character sets */
772 Vio_setWhiteChars(thee->sock, BHwhiteChars);
773 Vio_setCommChars(thee->sock, BHcommChars);
774
775 /* the counts */
776 *numF = 0;
777 *numL = 0;
778
779 /* initialization */
780 listNumber = -1;
781
782 /* create internal XDR buffer */
783 VASSERT( VNULL != (thee->pbuf=Vio_ctor("BUFF","XDR","localhost","0","w")));
784 Vio_setWhiteChars(thee->pbuf, BHwhiteChars);
785 Vio_setCommChars(thee->pbuf, BHcommChars);
786 VJMPERR3( 0 < Vio_printf(thee->pbuf,"%s\n","bhsingle") );
787
788 /* the first command should be putl */
789 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
790 VJMPERR3( 0 < Vio_printf(thee->pbuf,"%s",tok) );
791 VJMPERR1( strstr(tok,"putl") != VNULL );
792
793 /* number of colors (and possible RGB arrays) */
794 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&ncolor) );
795 VJMPERR3( 0 < Vio_printf(thee->pbuf," %d\n",ncolor) );
796 VJMPERR1( ncolor >= 0 );
797 if (ncolor == 0) {
798 /* non-color indexed mode */
799 } else if (ncolor > 0) {
800 for (j=0; j<ncolor; j++) {
801 if (dubl) {
802 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
803 red[j] = (float)dval;
804 } else {
805 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
806 red[j] = fval;
807 }
808 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",red[j]) );
809 }
810 VJMPERR3( 0 <= Vio_printf(thee->pbuf,"\n") );
811 for (j=0; j<ncolor; j++) {
812 if (dubl) {
813 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
814 green[j] = (float)dval;
815 } else {
816 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
817 green[j] = fval;
818 }
819 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",green[j]) );
820 }
821 VJMPERR3( 0 <= Vio_printf(thee->pbuf,"\n") );
822 for (j=0; j<ncolor; j++) {
823 if (dubl) {
824 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
825 blue[j] = (float)dval;
826 } else {
827 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
828 blue[j] = fval;
829 }
830 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",blue[j]) );
831 }
832 VJMPERR3( 0 <= Vio_printf(thee->pbuf,"\n") );
833 } else { VJMPERR1(0); }
834
835 /* process commands until "putl" is encountered again */
836 done = 0;
837 while (!done) {
838
839 /* get and process the next command token */
840 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
841 VJMPERR3( 0 < Vio_printf(thee->pbuf,"%s",tok) );
842
843 /* CASE: display list begin/end */
844 if ( strstr(tok,"list") != VNULL ) {
845
846 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&listNumberTmp) );
847 VJMPERR3( 0 < Vio_printf(thee->pbuf," %d\n",listNumberTmp) );
848 if ( listNumberTmp >= 0 ) {
849 VJMPERR1( listNumber < 0 );
850 listNumber = listNumberTmp;
851 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
852 } else {
853 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
854 VJMPERR1( listNumberTmp == -listNumber );
855 listNumber = -1;
856 }
857
858 /* CASE: line */
859 } else if ( strstr(tok,"line") != VNULL ) {
860
861 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
862 (*numL)++;
863 if (ncolor == 0) {
864 if (dubl) {
865 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
866 c[0] = (float)dval;
867 } else {
868 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
869 c[0] = fval;
870 }
871 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",c[0]) );
872 if (dubl) {
873 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
874 c[1] = (float)dval;
875 } else {
876 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
877 c[1] = fval;
878 }
879 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",c[1]) );
880 if (dubl) {
881 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
882 c[2] = (float)dval;
883 } else {
884 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
885 c[2] = fval;
886 }
887 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",c[2]) );
888 } else { /* (ncolor > 0) */
889 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&myColor) );
890 VJMPERR3( 0 < Vio_printf(thee->pbuf," %d",myColor) );
891 c[0] = red[ myColor - 1 ];
892 c[1] = green[ myColor - 1 ];
893 c[2] = blue[ myColor - 1 ];
894 }
895 c[3] = 0.0;
896 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&numPV) );
897 VJMPERR3( 0 < Vio_printf(thee->pbuf," %d\n",numPV) );
898 for (j=0; j<numPV; j++) {
899 if (dubl) {
900 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
901 x[j] = (float)dval;
902 } else {
903 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
904 x[j] = fval;
905 }
906 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",x[j]) );
907 }
908 for (j=0; j<numPV; j++) {
909 if (dubl) {
910 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
911 y[j] = (float)dval;
912 } else {
913 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
914 y[j] = fval;
915 }
916 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",y[j]) );
917 }
918 for (j=0; j<numPV; j++) {
919 if (dubl) {
920 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
921 z[j] = (float)dval;
922 } else {
923 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
924 z[j] = fval;
925 }
926 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",z[j]) );
927 }
928 VJMPERR3( 0 <= Vio_printf(thee->pbuf,"\n") );
929
930 /* CASE: fill */
931 } else if ( strstr(tok,"fill") != VNULL ) {
932
933 VJMPERR1( (0<=listNumber) && (listNumber<=9) );
934 (*numF)++;
935 if (ncolor == 0) {
936 if (dubl) {
937 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
938 c[0] = (float)dval;
939 } else {
940 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
941 c[0] = fval;
942 }
943 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",c[0]) );
944 if (dubl) {
945 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
946 c[1] = (float)dval;
947 } else {
948 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
949 c[1] = fval;
950 }
951 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",c[1]) );
952 if (dubl) {
953 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
954 c[2] = (float)dval;
955 } else {
956 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
957 c[2] = fval;
958 }
959 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",c[2]) );
960 } else { /* (ncolor > 0) */
961 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&myColor) );
962 VJMPERR3( 0 < Vio_printf(thee->pbuf," %d",myColor) );
963 c[0] = red[ myColor - 1 ];
964 c[1] = green[ myColor - 1 ];
965 c[2] = blue[ myColor - 1 ];
966 }
967 c[3] = 0.0;
968 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&numPV) );
969 VJMPERR3( 0 < Vio_printf(thee->pbuf," %d\n",numPV) );
970 for (j=0; j<numPV; j++) {
971 if (dubl) {
972 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
973 x[j] = (float)dval;
974 } else {
975 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
976 x[j] = fval;
977 }
978 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",x[j]) );
979 }
980 for (j=0; j<numPV; j++) {
981 if (dubl) {
982 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
983 y[j] = (float)dval;
984 } else {
985 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
986 y[j] = fval;
987 }
988 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",y[j]) );
989 }
990 for (j=0; j<numPV; j++) {
991 if (dubl) {
992 VJMPERR1( 1==Vio_scanf(thee->sock,"%le",&dval) );
993 z[j] = (float)dval;
994 } else {
995 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
996 z[j] = fval;
997 }
998 VJMPERR3( 0 < Vio_printf(thee->pbuf," %e",z[j]) );
999 }
1000 VJMPERR3( 0 <= Vio_printf(thee->pbuf,"\n") );
1001
1002 /* CASE: putl */
1003 } else if ( strstr(tok,"putl") != VNULL ) {
1004
1005 VJMPERR1( listNumber < 0 );
1006 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&ikey) );
1007 VJMPERR3( 0 < Vio_printf(thee->pbuf," %d\n",ikey) );
1008 VJMPERR1( ikey == -1 );
1009 done = 1;
1010
1011 } else { VJMPERR1(0); }
1012 }
1013
1014 /* return with no errors */
1015 theBufferSize = Vio_bufSize(thee->pbuf);
1016 theBuffer = Vio_bufGive(thee->pbuf);
1017 Vio_dtor( &(thee->pbuf) );
1018 return 1;
1019
1020 VERROR1:
1021 fprintf(stderr,"getBH: problem reading BH data.\n");
1022 theBufferSize = 0;
1023 theBuffer = VNULL;
1024 Vio_dtor( &(thee->pbuf) );
1025 return 0;
1026
1027 VERROR2:
1028 fprintf(stderr,"getBH: BH data must be in ASC or XDR.\n");
1029 theBufferSize = 0;
1030 theBuffer = VNULL;
1031 Vio_dtor( &(thee->pbuf) );
1032 return 0;
1033
1034 VERROR3:
1035 fprintf(stderr,"getBH: Problem writing to internal XDR buffer.\n");
1036 theBufferSize = 0;
1037 theBuffer = VNULL;
1038 Vio_dtor( &(thee->pbuf) );
1039 return 0;
1040 }
1041
1042 /*
1043 * ***************************************************************************
1044 * Purpose: Read an OFF-file (Geomview format)
1045 *
1046 * Notes: Typical "OFF" input file:
1047 *
1048 * ###################################################################
1049 * OFF # filetype key
1050 * 1231 1078 4166 # number of V,S,E (E is ignored)
1051 * 28.75 8.50 -28.25 # first vertex (x-y-z coords)
1052 * ...
1053 * -21.90 47.90 17.50 # last vertex (x-y-z coords)
1054 * 3 6 8 0 0.80 0.10 0.10 # first polygon (#verts, verts, RGBA)
1055 * ...
1056 * 3 121 128 130 0.80 0.10 0.10 # last polygon (#verts, verts, RGBA)
1057 * ###################################################################
1058 *
1059 * Note that there might be a 4th real number on each line in an OFF file;
1060 * this is interpretted as an ALPHA (GAMMA) value for that polygon.
1061 * We currently do not allow the extra ALPHA values in our OFF read
1062 * routine; files with ALPHA values on any line will generate an error.
1063 *
1064 * Author: Michael Holst
1065 * ***************************************************************************
1066 */
1067 VPRIVATE int getOFF(Vgl *thee,
1068 int *numV, int *numP, Vertx **vert, Polyg **poly)
1069 {
1070 int i, j, dummy;
1071 float fval;
1072
1073 /* we can do ASC or XDR */
1074 VJMPERR2( (thee->sock->frmt == VIO_ASC) || (thee->sock->frmt == VIO_XDR) );
1075
1076 /* set the comment/whitespace character sets */
1077 Vio_setWhiteChars(thee->sock, OFFwhiteChars);
1078 Vio_setCommChars(thee->sock, OFFcommChars);
1079
1080 /* next line has vertex/simplex/edge information */
1081 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",numV) );
1082 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",numP) );
1083 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&dummy) );
1084
1085 /* get new space -- we DO know A PRIORI how big arrays need to be */
1086 if (*numV > 0) (*vert) = (Vertx*)calloc( *numV, sizeof(Vertx) );
1087 if (*numP > 0) (*poly) = (Polyg*)calloc( *numP, sizeof(Polyg) );
1088
1089 /* read in the vertices */
1090 for (i=0; i<*numV; i++) {
1091 for (j=0; j<3; j++) {
1092 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
1093 (*vert)[i].x[j] = fval;
1094 }
1095 #if 0
1096 fprintf(stderr,"v[%d]=< %e , %e , %e >\n",
1097 i,(*vert)[i].x[0],(*vert)[i].x[1],(*vert)[i].x[2]);
1098 #endif
1099 }
1100
1101 /* read in the polygons */
1102 for (i=0; i<*numP; i++) {
1103
1104 /* number of vertices in this polygon */
1105 VJMPERR1( 1==Vio_scanf(thee->sock,"%d", &((*poly)[i].numPV) ) );
1106 VJMPERR1( (3 <= (*poly)[i].numPV) && ((*poly)[i].numPV <= 15) );
1107
1108 /* the vertex numbers for this polygon */
1109 for (j=0; j<(*poly)[i].numPV; j++)
1110 VJMPERR1( 1==Vio_scanf(thee->sock,"%d", (*poly)[i].v+j) );
1111
1112 /* get (r,g,b) colors for this polygon */
1113 for (j=0; j<3; j++) {
1114 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
1115 (*poly)[i].c[j] = fval;
1116 }
1117
1118 /* set alpha to zero; assume not in the file as part of color! */
1119 (*poly)[i].c[3] = 0.0;
1120
1121 #if 0
1122 fprintf(stderr,"s[%d]=< %d , %d , %d > < %e, %e, %e >\n",
1123 i,(*poly)[i].v[0],(*poly)[i].v[1],(*poly)[i].v[2],
1124 (*poly)[i].c[0],(*poly)[i].c[1],(*poly)[i].c[2]);
1125 #endif
1126 }
1127 VJMPERR1( i == *numP );
1128
1129 /* return with no errors */
1130 return 1;
1131
1132 VERROR1:
1133 fprintf(stderr,"getOFF: problem reading OFF data.\n");
1134 return 0;
1135
1136 VERROR2:
1137 fprintf(stderr,"getOFF: OFF data must be in ASC or XDR.\n");
1138 return 0;
1139 }
1140
1141 /*
1142 * ***************************************************************************
1143 * Purpose: Read an PDB-file (Protein database format)
1144 *
1145 * Notes: Typical "pdb" input file and the standard coloring of atoms:
1146 *
1147 * ###################################################################
1148 * PDB # filetype key
1149 * 9 1651 # number of RGBA colors and number of atoms
1150 * # RRR GGG BBB AAA # RGBA order
1151 * C 0.2 0.2 0.2 1.0 # carbon -- grey/black
1152 * O 1.0 0.0 0.0 1.0 # oxygen -- red
1153 * N 0.0 0.0 1.0 1.0 # nitrogen -- blue
1154 * H 1.0 1.0 1.0 1.0 # hydrogen -- white/not shown
1155 * P 0.0 1.0 0.0 1.0 # phosphorous -- green/varies
1156 * S 1.0 1.0 0.0 1.0 # sulfur -- yellow
1157 * L 0.0 0.0 0.0 1.0 # lithium -- anything/nothing?
1158 * F 1.0 0.0 1.0 1.0 # fluorine -- pink/purple/anything
1159 * I 0.0 1.0 1.0 1.0 # iodine -- anything
1160 * #
1161 * ATOM 1 OXT G 1 13.976 23.322 9.208 -0.760 1.600
1162 * ... ...
1163 * ATOM 1651 OXT G 91 14.213 22.233 8.283 -0.760 1.600
1164 * ###################################################################
1165 *
1166 * The "ATOM" lines specify one atom per line in a PQR file is as follows:
1167 *
1168 * What # Type ResName ResNum X-coord Y-coord Z-coord Chrg Radius
1169 * ---- --- ---- ------- ------ ------- ------- ------- ------ ------
1170 * ATOM 28 Oxyz Cxyz 2 12.590 25.761 1.393 -0.89 1.600
1171 *
1172 * The "ATOM" lines specify one atom per line in a PDB file is as follows:
1173 *
1174 * What # Type ResName ? ResNum X-coord Y-coord Z-coord ??? ???
1175 * ---- --- ---- ------- - ------ ------- ------- ------- ------ ------
1176 * ATOM 124 H THR A 12 -2.924 33.977 32.167 0.00 15.00 etc
1177 *
1178 * Author: Michael Holst
1179 * ***************************************************************************
1180 */
1181 VPRIVATE int getPDB(Vgl *thee,
1182 int *numV, int *numP, Vertx **vert, Polyg **poly)
1183 {
1184 int i, j, idum, numC, found;
1185 float fval, radius, acolor[100][80];
1186 char cdum[80], atype[80], aname[100][80];
1187
1188 /* we only do ASC */
1189 VJMPERR2( thee->sock->frmt == VIO_ASC );
1190
1191 /* set the comment/whitespace character sets */
1192 Vio_setWhiteChars(thee->sock, PDBwhiteChars);
1193 Vio_setCommChars(thee->sock, PDBcommChars);
1194
1195 /* next line has color and vertex information */
1196 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&numC) );
1197 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",numV) );
1198 *numP = 0;
1199 VJMPERR1( numC <= 100 );
1200
1201 /* get new space -- we DO know A PRIORI how big arrays need to be */
1202 if (*numV > 0) (*vert) = (Vertx*)calloc( *numV, sizeof(Vertx) );
1203
1204 /* read in the colors */
1205 for (i=0; i<numC; i++) {
1206 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",aname[i]) );
1207 for (j=0; j<4; j++) {
1208 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
1209 acolor[i][j] = fval;
1210 }
1211 }
1212
1213 /* read in the atoms */
1214 for (i=0; i<*numV; i++) {
1215
1216 /* grab the atom name token */
1217 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",cdum) );
1218
1219 /* grab the atom number token */
1220 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&idum) );
1221
1222 /* grab the atom type token */
1223 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",atype) );
1224
1225 /* grab the residue name token */
1226 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",cdum) );
1227
1228 /* grab the residue number token */
1229 VJMPERR1( 1==Vio_scanf(thee->sock,"%d",&idum) );
1230
1231 for (j=0; j<3; j++) {
1232 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
1233 (*vert)[i].x[j] = fval;
1234 }
1235
1236 /* grab the charge token */
1237 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
1238
1239 /* grab the radius token */
1240 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
1241 radius = 1.2 * fval;
1242 if (radius == 0.0) radius = 1.0;
1243 (*vert)[i].r = radius;
1244
1245 /* setup some colors based on atom type */
1246 (*vert)[i].c[0] = 1.0;
1247 (*vert)[i].c[1] = 1.0;
1248 (*vert)[i].c[2] = 1.0;
1249 (*vert)[i].c[3] = 1.0;
1250 found = 0;
1251 for (j=0; j<numC; j++) {
1252 if (atype[0] == aname[j][0]) {
1253 (*vert)[i].c[0] = acolor[j][0];
1254 (*vert)[i].c[1] = acolor[j][1];
1255 (*vert)[i].c[2] = acolor[j][2];
1256 (*vert)[i].c[3] = acolor[j][3];
1257 found = 1;
1258 }
1259 }
1260 if (!found) fprintf(stderr,"getPDB: unknown atom <%s>\n", atype);
1261 }
1262
1263 /* return with no errors */
1264 return 1;
1265
1266 VERROR1:
1267 fprintf(stderr,"getPDB: problem reading PDB data.\n");
1268 return 0;
1269
1270 VERROR2:
1271 fprintf(stderr,"getPDB: PDB data must be in ASC.\n");
1272 return 0;
1273 }
1274
1275 /*
1276 * ***************************************************************************
1277 * Purpose: Read an IV-file (Inventor format)
1278 *
1279 * Notes: Typical "IV" input file:
1280 *
1281 * #################################################################
1282 * #Inventor V2.1 ascii
1283 * Separator {
1284 * Blah-Blah-Blah
1285 * Coordinate3 {
1286 * point [ 10.8343 5.71745 196.846,
1287 * ...
1288 * 16.2891 -183.083 83.8652 ]
1289 * }
1290 * IndexedFaceSet {
1291 * coordIndex [ 2, 0, 3, -1, 1, 0, 4, -1,
1292 * ...
1293 * 46, 16, 39, -1 ]
1294 * }
1295 * }
1296 * #################################################################
1297 *
1298 * Author: Michael Holst
1299 * ***************************************************************************
1300 */
1301 VPRIVATE int getIV(Vgl *thee,
1302 int *numV, int *numP, Vertx **vert, Polyg **poly)
1303 {
1304 int i, j, k, done, ival;
1305 float fval;
1306 char tok[VMAX_BUFSIZE];
1307
1308 Vertx *vertOld = VNULL;
1309 Polyg *polyOld = VNULL;
1310 int numVmaxOld = 0;
1311 int numPmaxOld = 0;
1312 int numVmax = 0;
1313 int numPmax = 0;
1314
1315 /* we only do ASC */
1316 VJMPERR2( thee->sock->frmt == VIO_ASC );
1317
1318 /* set the comment/whitespace character sets */
1319 Vio_setWhiteChars(thee->sock, INVwhiteChars);
1320 Vio_setCommChars(thee->sock, INVcommChars);
1321
1322 /* get new space -- we DO NOT know A PRIORI how big arrays need to be */
1323 numVmax = 0;
1324 numPmax = 0;
1325
1326 /* need to skip down to the "Coordinate3" label to start vertex list */
1327 done = 0;
1328 i = 0;
1329 while ((!done) && (i < tokMaxBODY)) {
1330 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
1331 if ( strstr(tok,"Coordinate3") != VNULL ) done = 1;
1332 i++;
1333 }
1334 VJMPERR1( i < tokMaxBODY );
1335
1336 /* need to skip down to the "[" label to start vertex list */
1337 done = 0;
1338 i = 0;
1339 while ((!done) && (i < tokMaxBODY)) {
1340 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
1341 if ( strstr(tok,"[") != VNULL ) done = 1;
1342 i++;
1343 }
1344 VJMPERR1( i < tokMaxBODY );
1345
1346 /* read in the vertices */
1347 done = 0;
1348 i = 0;
1349 while (!done) {
1350 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
1351 if ( strstr(tok,"]") != VNULL ) done = 1;
1352 else {
1353 if (i == numVmax) {
1354 numVmaxOld = numVmax;
1355 vertOld = (*vert);
1356 numVmax = 2*(numVmaxOld+1);
1357 (*vert) = (Vertx*)calloc( numVmax, sizeof(Vertx) );
1358 if (vertOld != VNULL) {
1359 for (j=0; j<numVmaxOld; j++)
1360 for (k=0; k<3; k++)
1361 (*vert)[j].x[k] = vertOld[j].x[k];
1362 free( vertOld );
1363 vertOld = VNULL;
1364 }
1365 }
1366 sscanf(tok,"%e",&fval);
1367 (*vert)[i].x[0] = fval;
1368 for (j=1; j<3; j++) {
1369 VJMPERR1( 1==Vio_scanf(thee->sock,"%e",&fval) );
1370 (*vert)[i].x[j] = fval;
1371 }
1372 i++;
1373 }
1374 }
1375 *numV = i;
1376
1377 /* need to skip down to the "IndexedFaceSet" label to start polygon list */
1378 done = 0;
1379 i = 0;
1380 while ((!done) && (i < tokMaxBODY)) {
1381 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
1382 if ( strstr(tok,"IndexedFaceSet") != VNULL ) done = 1;
1383 i++;
1384 }
1385 VJMPERR1( i < tokMaxBODY );
1386
1387 /* need to skip down to the "[" label to start polygon list */
1388 done = 0;
1389 i = 0;
1390 while ((!done) && (i < tokMaxBODY)) {
1391 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
1392 if ( strstr(tok,"[") != VNULL ) done = 1;
1393 i++;
1394 }
1395 VJMPERR1( i < tokMaxBODY );
1396
1397 /* read in the vertices */
1398 done = 0;
1399 i = 0;
1400 while (!done) {
1401 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
1402 if ( strstr(tok,"]") != VNULL ) done = 1;
1403 else {
1404 if (i == numPmax) {
1405 numPmaxOld = numPmax;
1406 polyOld = (*poly);
1407 numPmax = 2*(numPmaxOld+1);
1408 (*poly) = (Polyg*)calloc( numPmax, sizeof(Polyg) );
1409 if (polyOld != VNULL) {
1410 for (j=0; j<numPmaxOld; j++) {
1411 (*poly)[j].numPV = polyOld[j].numPV;
1412 for (k=0; k<(*poly)[j].numPV; k++)
1413 (*poly)[j].v[k] = polyOld[j].v[k];
1414 for (k=0; k<4; k++)
1415 (*poly)[j].c[k] = polyOld[j].c[k];
1416 }
1417 free( polyOld );
1418 polyOld = VNULL;
1419 }
1420 }
1421 sscanf(tok,"%d", &ival);
1422 if (ival == -1) {
1423 VJMPERR1( (3<=(*poly)[i].numPV) && ((*poly)[i].numPV<=15) );
1424 for (j=0; j<4; j++) (*poly)[i].c[j] = (float)0.6;
1425 i++;
1426 } else {
1427 (*poly)[i].v[ (*poly)[i].numPV ] = ival;
1428
1429 /* ASSUME WAS INITIALIZED TO ZERO BY CALLOC!!! */
1430 (*poly)[i].numPV++;
1431 }
1432 }
1433 }
1434 *numP = i;
1435
1436 /* remalloc vertices so we have just enough space */
1437 if (*numV > 0) {
1438 vertOld = (*vert);
1439 (*vert) = (Vertx*)calloc( *numV, sizeof(Vertx) );
1440 VJMPERR1( (*vert) != VNULL );
1441 for (j=0; j<*numV; j++)
1442 for (k=0; k<3; k++)
1443 (*vert)[j].x[k] = vertOld[j].x[k];
1444 free( vertOld );
1445 vertOld = VNULL;
1446 }
1447
1448 /* remalloc polygons so we have just enough space */
1449 if (*numP > 0) {
1450 polyOld = (*poly);
1451 (*poly) = (Polyg*)calloc( *numP, sizeof(Polyg) );
1452 VJMPERR1( (*poly) != VNULL );
1453 for (j=0; j<*numP; j++) {
1454 (*poly)[j].numPV = polyOld[j].numPV;
1455 for (k=0; k<(*poly)[j].numPV; k++)
1456 (*poly)[j].v[k] = polyOld[j].v[k];
1457 for (k=0; k<4; k++)
1458 (*poly)[j].c[k] = polyOld[j].c[k];
1459 }
1460 free( polyOld );
1461 polyOld = VNULL;
1462 }
1463
1464 /* return with no errors */
1465 return 1;
1466
1467 VERROR1:
1468 fprintf(stderr,"getIV: problem reading IV data.\n");
1469 return 0;
1470
1471 VERROR2:
1472 fprintf(stderr,"getIV: IV data must be in ASC.\n");
1473 return 0;
1474 }
1475
1476 /*
1477 * ***************************************************************************
1478 * Purpose: Read the polygons
1479 *
1480 * Author: Michael Holst
1481 * ***************************************************************************
1482 */
1483 VPRIVATE int getPolygs(Vgl *thee)
1484 {
1485 int dtype, tokCount, done;
1486 char tok[VMAX_BUFSIZE];
1487 int numV = 0;
1488 int numP = 0;
1489 int numF = 0;
1490 int numL = 0;
1491 Vertx *vert = VNULL;
1492 Polyg *poly = VNULL;
1493
1494 /* common minimal settings for white space and comment character sets */
1495 Vio_setWhiteChars(thee->sock," \t\n");
1496 Vio_setCommChars(thee->sock,"");
1497
1498 /* determine the input file format */
1499 tokCount = 0;
1500 done = 0;
1501 dtype = 0;
1502 while ((!dtype) && (tokCount < tokMaxHEAD) && (!done) ) {
1503 VJMPERR1( 1==Vio_scanf(thee->sock,"%s",tok) );
1504 if (tok != VNULL) {
1505 if ( strstr(tok,"#Inventor") != VNULL ) dtype = 1;
1506 else if ( strstr(tok,"OFF") != VNULL ) dtype = 2;
1507 else if ( strstr(tok,"PDB") != VNULL ) dtype = 3;
1508 else if ( strstr(tok,"bhsingle") != VNULL ) dtype = 4;
1509 else if ( strstr(tok,"bhdouble") != VNULL ) dtype = 5;
1510 else if ( strstr(tok,"mcsf_begin") != VNULL ) dtype = 6;
1511 else if ( strstr(tok,"mcef_begin") != VNULL ) dtype = 7;
1512 tokCount++;
1513 } else done = 1;
1514 }
1515
1516 /* take action based on classification */
1517 if (dtype == 1) {
1518 fprintf(stderr,"%s: Hit with an IV file..", PR);
1519 VJMPERR1( getIV(thee, &numV, &numP, &vert, &poly) );
1520 fprintf(stderr,"..%d vertices and %d polygons.\n", numV, numP);
1521 VJMPERR1( poly2bh(thee, numV, numP, vert, poly) );
1522 } else if (dtype == 2) {
1523 fprintf(stderr,"%s: Hit with an OFF file..", PR);
1524 VJMPERR1( getOFF(thee, &numV, &numP, &vert, &poly) );
1525 fprintf(stderr,"..%d vertices and %d polygons.\n", numV, numP);
1526 VJMPERR1( poly2bh(thee, numV, numP, vert, poly) );
1527 } else if (dtype == 3) {
1528 fprintf(stderr,"%s: Hit with a PDB file..", PR);
1529 VJMPERR1( getPDB(thee, &numV, &numP, &vert, &poly) );
1530 fprintf(stderr,"..%d vertices (atoms).\n", numV);
1531 VJMPERR1( poly2bh(thee, numV, numP, vert, poly) );
1532 } else if (dtype == 4) {
1533 fprintf(stderr,"%s: Hit with a BHsingle file..", PR);
1534 VJMPERR1( getBH(thee, &numF, &numL, 0) );
1535 fprintf(stderr,"..%d files and %d lines.\n", numF, numL);
1536 } else if (dtype == 5) {
1537 fprintf(stderr,"%s: Hit with a BHdouble file..", PR);
1538 VJMPERR1( getBH(thee, &numF, &numL, 1) );
1539 fprintf(stderr,"..%d files and %d lines.\n", numF, numL);
1540 } else {
1541 if (dtype == 6) {
1542 fprintf(stderr,"%s: Unable to display MCSF files directly.\n", PR);
1543 } else if (dtype == 7) {
1544 fprintf(stderr,"%s: Unable to display MCEF files directly.\n", PR);
1545 } else {
1546 fprintf(stderr,"%s: Problem understanding the file header.\n", PR);
1547 }
1548 }
1549 /* release data space */
1550 if ( vert != VNULL ) {
1551 free( vert );
1552 vert = VNULL;
1553 }
1554 if ( poly != VNULL ) {
1555 free( poly );
1556 poly = VNULL;
1557 }
1558 return 1;
1559
1560 VERROR1:
1561 fprintf(stderr,"getPolygs: problem reading data.\n");
1562 /* release data space */
1563 if ( vert != VNULL ) {
1564 free( vert );
1565 vert = VNULL;
1566 }
1567 if ( poly != VNULL ) {
1568 free( poly );
1569 poly = VNULL;
1570 }
1571 return 0;
1572 }
1573
1574 /*
1575 * ***************************************************************************
1576 * Purpose: Build the display lists
1577 *
1578 * Author: Michael Holst
1579 * ***************************************************************************
1580 */
1581 int buildDisplayLists(Vgl *thee)
1582 {
1583 int rc;
1584
1585 /* check the socket first */
1586 if (thee->sock == VNULL) return 0;
1587
1588 /* call (non-blocking) accept */
1589 if (0 <= Vio_accept(thee->sock,1)) {
1590
1591 /* get the new polygons */
1592 rc=getPolygs(thee);
1593
1594 /* free input subsocket to setup for another accept */
1595 Vio_acceptFree(thee->sock);
1596
1597 /* return with no errors (without polygons) */
1598 if (rc == 0) {
1599 fprintf(stderr,"buildDisplayLists: hmmm...didn't get polygons!\n");
1600 return 0;
1601
1602 /* return with no errors (with polygons) after rendering */
1603 } else {
1604 VJMPERR1( bh2gl(thee) );
1605 return 1;
1606 }
1607
1608 } else {
1609 /* return with no errors (without polygons) */
1610 return 0;
1611 }
1612
1613 VERROR1:
1614 fprintf(stderr,"buildDisplayLists: problem with data\n");
1615 return 0;
1616 }
1617
1618 /*
1619 * ***************************************************************************
1620 * Routine: main
1621 *
1622 * Purpose: Read data from file/unix-or-inet-socket
1623 * and display using VGL library.
1624 *
1625 * Notes: This code currently supports the following data formats:
1626 *
1627 * (1) OFF --> Geomview-style data files
1628 * (2) IV --> Inventor-style data files
1629 * (3) PDB --> Protein Databank-style data files
1630 * (4) BH --> Bank/Holst-style compressed data files
1631 *
1632 * Example: The following brings up SG listening to AF_UNIX socket 1:
1633 *
1634 * ./mcsg -nopanels -wpos 215,208@0,764 -Mcs 1
1635 *
1636 * Author: Michael Holst
1637 * ***************************************************************************
1638 */
1639 int main(int argc, char *argv[])
1640 {
1641 int mode, argi, xsize, ysize, xpos, ypos;
1642 char geomInfo[80], *buf[80];
1643 char dataform[80], socktype[80], hostname[80], filename[80];
1644
1645 Vgl *vgl = VNULL;
1646
1647 /* default window size and position */
1648 xsize = 500;
1649 ysize = 500;
1650 xpos = 0;
1651 ypos = 0;
1652
1653 /* defaults */
1654 strncpy(filename,"-1",80);
1655 strncpy(dataform,"XDR",80);
1656 strncpy(socktype,"FILE",80);
1657 strncpy(hostname,"localhost",80);
1658 strncpy(PR,argv[0],80);
1659
1660 /* determine startup mode based on name of invoked binary */
1661 #if 0
1662 mode = 0;
1663 #else
1664 if ( (!strcmp(PR,"mcsg")) || (!strcmp(PR,"./mcsg")) ) {
1665 mode = 0;
1666 } else {
1667 if (Vgl_capability() > 0) {
1668 mode = 1;
1669 /* change default socktype to "NONE" */
1670 strncpy(socktype,"NONE",80);
1671 } else {
1672 mode = 0;
1673 }
1674 }
1675 #endif
1676
1677 /* handles args; determine which Vio object to create (file/unix/inet) */
1678 if (argc > 1) {
1679 argi = 1;
1680 while (argi < argc) {
1681 if ((!strcmp(argv[argi],"-h")) || (!strcmp(argv[argi],"--help"))) {
1682 VJMPERR1(0);
1683 } else if (!strcmp(argv[argi],"-nopanels")) {
1684 argi++;
1685 } else if (!strcmp(argv[argi],"-asc")) {
1686 argi++;
1687 strncpy(dataform,"ASC",80);
1688 } else if (!strcmp(argv[argi],"-xdr")) {
1689 argi++;
1690 strncpy(dataform,"XDR",80);
1691 } else if (!strcmp(argv[argi],"-wpos")) {
1692 argi++;
1693 if (argi < argc) {
1694 strncpy(geomInfo,argv[argi],80);
1695 (void)Vnm_gentokens(geomInfo, buf, 80, ",@", "");
1696 if (buf[0] != VNULL) xsize = atoi(buf[0]);
1697 if (buf[1] != VNULL) ysize = atoi(buf[1]);
1698 if (buf[2] != VNULL) xpos = atoi(buf[2]);
1699 if (buf[3] != VNULL) ypos = atoi(buf[3]);
1700 argi++;
1701 }
1702 } else if (!strcmp(argv[argi],"-Mci")) {
1703 argi++;
1704 if (argi < argc) sprintf(filename,"%s", argv[argi]);
1705 else sprintf(filename,"%s", "-1");
1706 strncpy(socktype,"INET",80);
1707 argi++;
1708 } else if (!strcmp(argv[argi],"-Mcs")) {
1709 argi++;
1710 if (argi < argc) sprintf(filename,"%s", argv[argi]);
1711 else sprintf(filename,"%s", "-1");
1712 strncpy(socktype,"UNIX",80);
1713 argi++;
1714 } else if (!strcmp(argv[argi],"-Mcf")) {
1715 argi++;
1716 if (argi < argc) sprintf(filename,"%s", argv[argi]);
1717 else sprintf(filename,"%s", "input");
1718 strncpy(socktype,"FILE",80);
1719 argi++;
1720 } else {
1721 sprintf(filename,"%s", argv[argi]);
1722 strncpy(socktype,"FILE",80);
1723 argi++;
1724 }
1725 }
1726 } else if (mode == 0) {
1727 VJMPERR1(0);
1728 }
1729
1730 /* startup vio */
1731 Vio_start();
1732
1733 /* startup and shutdown the trackball rotator */
1734 vgl = Vgl_ctor(mode,socktype,dataform,hostname,filename,
1735 xsize,ysize,xpos,ypos,buildDisplayLists);
1736 Vgl_dtor(&vgl);
1737
1738 /* stop vio */
1739 Vio_stop();
1740
1741 /* return without error */
1742 return 0;
1743
1744 /* return with error */
1745 VERROR1:
1746 fprintf(stderr,"\n");
1747 fprintf(stderr,
1748 "Usage: %s [ -nopanels ] [ -wpos xsize,ysize@[xmin,ymin] ]\n",PR);
1749 fprintf(stderr,
1750 " [ -asc | -xdr ] [ -Mcs | -Mci ]\n");
1751 fprintf(stderr,
1752 " filename | domainSocketName | inetSocketNumber\n");
1753 fprintf(stderr,"\n");
1754 fprintf(stderr," Parameter interpretation:\n\n");
1755 fprintf(stderr," -nopanels= for geomview compatibility (ignored)\n");
1756 fprintf(stderr," -wpos = initial window size and location\n");
1757 fprintf(stderr," -asc = input stream is ASC data\n");
1758 fprintf(stderr," -xdr = input stream is XDR data (default)\n");
1759 fprintf(stderr," -Mcf = input device is FILE (default)\n");
1760 fprintf(stderr," -Mcs = input device is UNIX domain socket\n");
1761 fprintf(stderr," -Mci = input device is INET network socket\n");
1762 fprintf(stderr," filename = input device filename or portnumber:\n");
1763 fprintf(stderr," If -Mcf : filename=FILE name\n");
1764 fprintf(stderr," If -Mcs : filename=UNIX domain socket name\n");
1765 fprintf(stderr," If -Mci : filename=INET socket port number\n");
1766 fprintf(stderr,"\n");
1767 return 0;
1768 }
1769