forked from PhilipLudington/Triangle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
showme.c
3375 lines (3276 loc) · 106 KB
/
showme.c
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************/
/* */
/* ,d88^^o 888 o o */
/* 8888 888o^88, o88^^o Y88b o / d8b d8b o88^^8o */
/* "Y88b 888 888 d888 b Y88b d8b / d888bdY88b d888 88b */
/* "Y88b, 888 888 8888 8 Y888/Y88b/ / Y88Y Y888b 8888oo888 */
/* o 8888 888 888 q888 p Y8/ Y8/ / YY Y888b q888 */
/* "oo88P" 888 888 "88oo" Y Y / Y888b "88oooo" */
/* */
/* A Display Program for Meshes and More. */
/* (showme.c) */
/* */
/* Version 1.6 */
/* July 28, 2005 */
/* */
/* Copyright 1996, 1998, 2005 */
/* Jonathan Richard Shewchuk */
/* 2360 Woolsey #H */
/* Berkeley, California 94705-1927 */
/* jrs@cs.berkeley.edu */
/* */
/* This program may be freely redistributed under the condition that the */
/* copyright notices (including this entire header and the copyright */
/* notice printed when the `-h' switch is selected) are not removed, and */
/* no compensation is received. Private, research, and institutional */
/* use is free. You may distribute modified versions of this code UNDER */
/* THE CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE TO IT IN THE */
/* SAME FILE REMAIN UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH SOURCE */
/* AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT CHARGE, AND CLEAR */
/* NOTICE IS GIVEN OF THE MODIFICATIONS. Distribution of this code as */
/* part of a commercial system is permissible ONLY BY DIRECT ARRANGEMENT */
/* WITH THE AUTHOR. (If you are not directly supplying this code to a */
/* customer, and you are instead telling them how they can obtain it for */
/* free, then you are not required to make any arrangement with me.) */
/* */
/* Hypertext instructions for Triangle are available on the Web at */
/* */
/* http://www.cs.cmu.edu/~quake/showme.html */
/* */
/* Show Me was created as part of the Archimedes project in the School of */
/* Computer Science at Carnegie Mellon University. Archimedes is a */
/* system for compiling parallel finite element solvers. For further */
/* information, see Anja Feldmann, Omar Ghattas, John R. Gilbert, Gary L. */
/* Miller, David R. O'Hallaron, Eric J. Schwabe, Jonathan R. Shewchuk, */
/* and Shang-Hua Teng. "Automated Parallel Solution of Unstructured PDE */
/* Problems." To appear in Communications of the ACM, we hope. */
/* */
/* If you make any improvements to this code, please please please let me */
/* know, so that I may obtain the improvements. Even if you don't change */
/* the code, I'd still love to hear what it's being used for. */
/* */
/* Disclaimer: Neither I nor Carnegie Mellon warrant this code in any way */
/* whatsoever. Use at your own risk. */
/* */
/*****************************************************************************/
/* For single precision (which will save some memory and reduce paging), */
/* write "#define SINGLE" below. */
/* */
/* For double precision (which will allow you to display triangulations of */
/* a finer resolution), leave SINGLE undefined. */
/* #define SINGLE */
#ifdef SINGLE
#define REAL float
#else
#define REAL double
#endif
/* Maximum number of characters in a file name (including the null). */
#define FILENAMESIZE 2048
/* Maximum number of characters in a line read from a file (including the */
/* null). */
#define INPUTLINESIZE 1024
#define STARTWIDTH 414
#define STARTHEIGHT 414
#define MINWIDTH 50
#define MINHEIGHT 50
#define BUTTONHEIGHT 21
#define BUTTONROWS 3
#define PANELHEIGHT (BUTTONHEIGHT * BUTTONROWS)
#define MAXCOLORS 64
#define IMAGE_TYPES 7
#define NOTHING -1
#define NODE 0
#define POLY 1
#define ELE 2
#define EDGE 3
#define PART 4
#define ADJ 5
#define VORO 6
#define STARTEXPLOSION 0.5
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
/* A necessary forward declaration. */
int load_image();
Display *display;
int screen;
Window rootwindow;
Window mainwindow;
Window quitwin;
Window leftwin;
Window rightwin;
Window upwin;
Window downwin;
Window resetwin;
Window pswin;
Window epswin;
Window expwin;
Window exppluswin;
Window expminuswin;
Window widthpluswin;
Window widthminuswin;
Window versionpluswin;
Window versionminuswin;
Window fillwin;
Window nodewin[2];
Window polywin[2];
Window elewin[2];
Window edgewin[2];
Window partwin[2];
Window adjwin[2];
Window voronoiwin[2];
int windowdepth;
XEvent event;
Colormap rootmap;
XFontStruct *font;
int width, height;
int black, white;
int showme_foreground;
GC fontgc;
GC blackfontgc;
GC linegc;
GC trianglegc;
int colors[MAXCOLORS];
XColor rgb[MAXCOLORS];
int color;
int start_image, current_image;
int start_inc, current_inc;
int loweriteration;
int line_width;
int loaded[2][IMAGE_TYPES];
REAL xlo[2][IMAGE_TYPES], ylo[2][IMAGE_TYPES];
REAL xhi[2][IMAGE_TYPES], yhi[2][IMAGE_TYPES];
REAL xscale, yscale;
REAL xoffset, yoffset;
int zoom;
int nodes[2], node_dim[2];
REAL *nodeptr[2];
int polynodes[2], poly_dim[2], polyedges[2], polyholes[2];
REAL *polynodeptr[2], *polyholeptr[2];
int *polyedgeptr[2];
int elems[2], ele_corners[2];
int *eleptr[2];
int edges[2];
int *edgeptr[2];
REAL *normptr[2];
int subdomains[2];
int *partpart[2];
REAL *partcenter[2], *partshift[2];
int adjsubdomains[2];
int *adjptr[2];
int vnodes[2], vnode_dim[2];
REAL *vnodeptr[2];
int vedges[2];
int *vedgeptr[2];
REAL *vnormptr[2];
int firstnumber[2];
int quiet, fillelem, bw_ps, explode;
REAL explosion;
char filename[FILENAMESIZE];
char nodefilename[2][FILENAMESIZE];
char polyfilename[2][FILENAMESIZE];
char elefilename[2][FILENAMESIZE];
char edgefilename[2][FILENAMESIZE];
char partfilename[2][FILENAMESIZE];
char adjfilename[2][FILENAMESIZE];
char vnodefilename[2][FILENAMESIZE];
char vedgefilename[2][FILENAMESIZE];
char *colorname[] = {"aquamarine", "red", "green yellow", "magenta",
"yellow", "green", "orange", "blue",
"white", "sandy brown", "cyan", "moccasin",
"cadet blue", "coral", "cornflower blue", "sky blue",
"firebrick", "forest green", "gold", "goldenrod",
"gray", "hot pink", "chartreuse", "pale violet red",
"indian red", "khaki", "lavender", "light blue",
"light gray", "light steel blue", "lime green", "azure",
"maroon", "medium aquamarine", "dodger blue", "honeydew",
"medium orchid", "medium sea green", "moccasin",
"medium slate blue", "medium spring green",
"medium turquoise", "medium violet red",
"orange red", "chocolate", "light goldenrod",
"orchid", "pale green", "pink", "plum",
"purple", "salmon", "sea green",
"sienna", "slate blue", "spring green",
"steel blue", "tan", "thistle", "turquoise",
"violet", "violet red", "wheat",
"yellow green"};
void syntax()
{
printf("showme [-bfw_Qh] input_file\n");
printf(" -b Black and white PostScript (default is color).\n");
printf(" -f Fill triangles of partitioned mesh with color.\n");
printf(" -w Set line width to some specified number.\n");
printf(" -Q Quiet: No terminal output except errors.\n");
printf(" -h Help: Detailed instructions for Show Me.\n");
exit(0);
}
void info()
{
printf("Show Me\n");
printf("A Display Program for Meshes and More.\n");
printf("Version 1.6\n\n");
printf(
"Copyright 1996 Jonathan Richard Shewchuk (bugs/comments to jrs@cs.cmu.edu)\n"
);
printf("School of Computer Science / Carnegie Mellon University\n");
printf("5000 Forbes Avenue / Pittsburgh, Pennsylvania 15213-3891\n");
printf(
"Created as part of the Archimedes project (tools for parallel FEM).\n");
printf(
"Supported in part by NSF Grant CMS-9318163 and an NSERC 1967 Scholarship.\n");
printf("There is no warranty whatsoever. Use at your own risk.\n");
#ifdef SINGLE
printf("This executable is compiled for single precision arithmetic.\n\n\n");
#else
printf("This executable is compiled for double precision arithmetic.\n\n\n");
#endif
printf(
"Show Me graphically displays the contents of geometric files, especially\n");
printf(
"those generated by Triangle, my two-dimensional quality mesh generator and\n"
);
printf(
"Delaunay triangulator. Show Me can also write images in PostScript form.\n");
printf(
"Show Me is also useful for checking the consistency of the files you create\n"
);
printf(
"as input to Triangle; Show Me does these checks more thoroughly than\n");
printf("Triangle does. The command syntax is:\n\n");
printf("showme [-bfw_Qh] input_file\n\n");
printf(
"The underscore indicates that a number should follow the -w switch.\n");
printf(
"input_file may be one of several types of file. It must have extension\n");
printf(
".node, .poly, .ele, .edge, .part, or .adj. If no extension is provided,\n");
printf(
"Show Me will assume the extension .ele. A .node file represents a set of\n");
printf(
"points; a .poly file represents a Planar Straight Line Graph; an .ele file\n"
);
printf(
"(coupled with a .node file) represents the elements of a mesh or the\n");
printf(
"triangles of a triangulation; an .edge file (coupled with a .node file)\n");
printf(
"represents a set of edges; a .part file specifies a partition of a mesh;\n");
printf(
"and a .adj file represents the adjacency graph defined by a partition.\n");
printf("\n");
printf("Command Line Switches:\n");
printf("\n");
printf(
" -b Makes all PostScript output black and white. If this switch is not\n"
);
printf(
" selected, color PostScript is used for partitioned meshes and\n");
printf(" adjacency graphs (.part and .adj files).\n");
printf(
" -f On color displays and in color PostScript, displays partitioned\n");
printf(
" meshes by filling triangles with color, rather than by coloring the\n"
);
printf(
" edges. This switch will result in a clearer picture if all\n");
printf(
" triangles are reasonably large, and a less clear picture if small\n");
printf(
" triangles are present. (There is also a button to toggle this\n");
printf(" behavior.)\n");
printf(
" -w Followed by an integer, specifies the line width used in all\n");
printf(
" images. (There are also buttons to change the line width.)\n");
printf(
" -Q Quiet: Suppresses all explanation of what Show Me is doing, unless\n"
);
printf(" an error occurs.\n");
printf(" -h Help: Displays these instructions.\n");
printf("\n");
printf("Controls:\n");
printf("\n");
printf(
" To zoom in on an image, point at the location where you want a closer\n");
printf(
" look, and click the left mouse button. To zoom out, click the right\n");
printf(
" mouse button. In either case, the point you click on will be centered in\n"
);
printf(
" the window. If you want to know the coordinates of a point, click the\n");
printf(
" middle mouse button; the coordinates will be printed on the terminal you\n"
);
printf(" invoked Show Me from.\n\n");
printf(
" If you resize the window, the image will grow or shrink to match.\n");
printf("\n");
printf(
" There is a panel of control buttons at the bottom of the Show Me window:\n"
);
printf("\n");
printf(" Quit: Shuts down Show Me.\n");
printf(" <, >, ^, v: Moves the image in the indicated direction.\n");
printf(
" Reset: Unzooms and centers the image in the window. When you switch from\n"
);
printf(
" one image to another, the viewing region does not change, so you may\n");
printf(
" need to reset the new image to make it fully visible. This often is\n");
printf(
" the case when switching between Delaunay triangulations and their\n");
printf(
" corresponding Voronoi diagrams, as Voronoi vertices can be far from the\n"
);
printf(" initial point set.\n");
printf(
" Width+, -: Increases or decreases the width of all lines and points.\n");
printf(
" Exp, +, -: These buttons appear only when you are viewing a partitioned\n"
);
printf(
" mesh (.part file). `Exp' toggles between an exploded and non-exploded\n"
);
printf(
" image of the mesh. The non-exploded image will not show the partition\n"
);
printf(
" on a black and white monitor. `+' and `-' allow you to adjust the\n");
printf(
" spacing between pieces of the mesh to better distinguish them.\n");
printf(
" Fill: This button appears only when you are viewing a partitioned mesh\n");
printf(
" (.part file). It toggles between color-filled triangles and colored\n");
printf(
" edges (as the -f switch does). Filled triangles look better when all\n");
printf(
" triangles are reasonably large; colored edges look better when there\n");
printf(" are very small triangles present.\n");
printf(
" PS: Creates a PostScript file containing the image you are viewing. If\n"
);
printf(
" the -b switch is selected, all PostScript output will be black and\n");
printf(
" white; otherwise, .part.ps and .adj.ps files will be color, independent\n"
);
printf(
" of whether you are using a color monitor. Normally the output will\n");
printf(
" preserve the properties of the image you see on the screen, including\n");
printf(
" zoom and line width; however, if black and white output is selected (-b\n"
);
printf(
" switch), partitioned meshes will always be drawn exploded. The output\n"
);
printf(
" file name depends on the image being viewed. If you want several\n");
printf(
" different snapshots (zooming in on different parts) of the same object,\n"
);
printf(
" you'll have to rename each file after Show Me creates it so that it\n");
printf(" isn't overwritten by the next snapshot.\n");
printf(
" EPS: Creates an encapsulated PostScript file, suitable for inclusion in\n"
);
printf(
" documents. Otherwise, this button is just like the PS button. (The\n");
printf(
" only difference is that .eps files lack a `showpage' command at the\n");
printf(" end.)\n\n");
printf(
" There are two nearly-identical rows of buttons that load different images\n"
);
printf(" from disk. Each row contains the following buttons:\n\n");
printf(" node: Loads a .node file.\n");
printf(
" poly: Loads a .poly file (and possibly an associated .node file).\n");
printf(" ele: Loads an .ele file (and associated .node file).\n");
printf(" edge: Loads an .edge file (and associated .node file).\n");
printf(
" part: Loads a .part file (and associated .node and .ele files).\n");
printf(
" adj: Loads an .adj file (and associated .node, .ele, and .part files).\n");
printf(" voro: Loads a .v.node and .v.edge file for a Voronoi diagram.\n");
printf("\n");
printf(
" Each row represents a different iteration number of the geometry files.\n");
printf(
" For a full explanation of iteration numbers, read the instructions for\n");
printf(
" Triangle. Briefly, iteration numbers are used to allow a user to easily\n"
);
printf(
" represent a sequence of related triangulations. Iteration numbers are\n");
printf(
" used in the names of geometry files; for instance, mymesh.3.ele is a\n");
printf(
" triangle file with iteration number three, and mymesh.ele has an implicit\n"
);
printf(" iteration number of zero.\n\n");
printf(
" The control buttons at the right end of each row display the two\n");
printf(
" iterations currently under view. These buttons can be clicked to\n");
printf(
" increase or decrease the iteration numbers, and thus conveniently view\n");
printf(" a sequence of meshes.\n\n");
printf(
" Show Me keeps each file in memory after loading it, but you can force\n");
printf(
" Show Me to reread a set of files (for one iteration number) by reclicking\n"
);
printf(
" the button that corresponds to the current image. This is convenient if\n"
);
printf(" you have changed a geometry file.\n\n");
printf("File Formats:\n\n");
printf(
" All files may contain comments prefixed by the character '#'. Points,\n");
printf(
" segments, holes, triangles, edges, and subdomains must be numbered\n");
printf(
" consecutively, starting from either 1 or 0. Whichever you choose, all\n");
printf(
" input files must be consistent (for any single iteration number); if the\n"
);
printf(
" nodes are numbered from 1, so must be all other objects. Show Me\n");
printf(
" automatically detects your choice while reading a .node (or .poly) file.\n"
);
printf(" Examples of these file formats are given below.\n\n");
printf(" .node files:\n");
printf(
" First line: <# of points> <dimension (must be 2)> <# of attributes>\n");
printf(
" <# of boundary markers (0 or 1)>\n"
);
printf(
" Remaining lines: <point #> <x> <y> [attributes] [boundary marker]\n");
printf("\n");
printf(
" The attributes, which are typically floating-point values of physical\n");
printf(
" quantities (such as mass or conductivity) associated with the nodes of\n"
);
printf(
" a finite element mesh, are ignored by Show Me. Show Me also ignores\n");
printf(
" boundary markers. See the instructions for Triangle to find out what\n");
printf(" attributes and boundary markers are.\n\n");
printf(" .poly files:\n");
printf(
" First line: <# of points> <dimension (must be 2)> <# of attributes>\n");
printf(
" <# of boundary markers (0 or 1)>\n"
);
printf(
" Following lines: <point #> <x> <y> [attributes] [boundary marker]\n");
printf(" One line: <# of segments> <# of boundary markers (0 or 1)>\n");
printf(
" Following lines: <segment #> <endpoint> <endpoint> [boundary marker]\n");
printf(" One line: <# of holes>\n");
printf(" Following lines: <hole #> <x> <y>\n");
printf(" [Optional additional lines that are ignored]\n\n");
printf(
" A .poly file represents a Planar Straight Line Graph (PSLG), an idea\n");
printf(
" familiar to computational geometers. By definition, a PSLG is just a\n");
printf(
" list of points and edges. A .poly file also contains some additional\n");
printf(" information.\n\n");
printf(
" The first section lists all the points, and is identical to the format\n"
);
printf(
" of .node files. <# of points> may be set to zero to indicate that the\n"
);
printf(
" points are listed in a separate .node file; .poly files produced by\n");
printf(
" Triangle always have this format. When Show Me reads such a file, it\n");
printf(" also reads the corresponding .node file.\n\n");
printf(
" The second section lists the segments. Segments are edges whose\n");
printf(
" presence in a triangulation produced from the PSLG is enforced. Each\n");
printf(
" segment is specified by listing the indices of its two endpoints. This\n"
);
printf(
" means that its endpoints must be included in the point list. Each\n");
printf(
" segment, like each point, may have a boundary marker, which is ignored\n"
);
printf(" by Show Me.\n\n");
printf(
" The third section lists holes and concavities that are desired in any\n");
printf(
" triangulation generated from the PSLG. Holes are specified by\n");
printf(" identifying a point inside each hole.\n\n");
printf(" .ele files:\n");
printf(
" First line: <# of triangles> <points per triangle> <# of attributes>\n");
printf(
" Remaining lines: <triangle #> <point> <point> <point> ... [attributes]\n"
);
printf("\n");
printf(
" Points are indices into the corresponding .node file. Show Me ignores\n"
);
printf(
" all but the first three points of each triangle; these should be the\n");
printf(
" corners listed in counterclockwise order around the triangle. The\n");
printf(" attributes are ignored by Show Me.\n\n");
printf(" .edge files:\n");
printf(" First line: <# of edges> <# of boundary markers (0 or 1)>\n");
printf(
" Following lines: <edge #> <endpoint> <endpoint> [boundary marker]\n");
printf("\n");
printf(
" Endpoints are indices into the corresponding .node file. The boundary\n"
);
printf(" markers are ignored by Show Me.\n\n");
printf(
" In Voronoi diagrams, one also finds a special kind of edge that is an\n");
printf(
" infinite ray with only one endpoint. For these edges, a different\n");
printf(" format is used:\n\n");
printf(" <edge #> <endpoint> -1 <direction x> <direction y>\n\n");
printf(
" The `direction' is a floating-point vector that indicates the direction\n"
);
printf(" of the infinite ray.\n\n");
printf(" .part files:\n");
printf(" First line: <# of triangles> <# of subdomains>\n");
printf(" Remaining lines: <triangle #> <subdomain #>\n\n");
printf(
" The set of triangles is partitioned by a .part file; each triangle is\n");
printf(" mapped to a subdomain.\n\n");
printf(" .adj files:\n");
printf(" First line: <# of subdomains>\n");
printf(" Remaining lines: <adjacency matrix entry>\n\n");
printf(
" An .adj file represents adjacencies between subdomains (presumably\n");
printf(" computed by a partitioner). The first line is followed by\n");
printf(
" (subdomains X subdomains) lines, each containing one entry of the\n");
printf(
" adjacency matrix. A nonzero entry indicates that two subdomains are\n");
printf(" adjacent (share a point).\n\n");
printf("Example:\n\n");
printf(
" Here is a sample file `box.poly' describing a square with a square hole:\n"
);
printf("\n");
printf(
" # A box with eight points in 2D, no attributes, no boundary marker.\n");
printf(" 8 2 0 0\n");
printf(" # Outer box has these vertices:\n");
printf(" 1 0 0\n");
printf(" 2 0 3\n");
printf(" 3 3 0\n");
printf(" 4 3 3\n");
printf(" # Inner square has these vertices:\n");
printf(" 5 1 1\n");
printf(" 6 1 2\n");
printf(" 7 2 1\n");
printf(" 8 2 2\n");
printf(" # Five segments without boundary markers.\n");
printf(" 5 0\n");
printf(" 1 1 2 # Left side of outer box.\n");
printf(" 2 5 7 # Segments 2 through 5 enclose the hole.\n");
printf(" 3 7 8\n");
printf(" 4 8 6\n");
printf(" 5 6 5\n");
printf(" # One hole in the middle of the inner square.\n");
printf(" 1\n");
printf(" 1 1.5 1.5\n\n");
printf(
" After this PSLG is triangulated by Triangle, the resulting triangulation\n"
);
printf(
" consists of a .node and .ele file. Here is the former, `box.1.node',\n");
printf(" which duplicates the points of the PSLG:\n\n");
printf(" 8 2 0 0\n");
printf(" 1 0 0\n");
printf(" 2 0 3\n");
printf(" 3 3 0\n");
printf(" 4 3 3\n");
printf(" 5 1 1\n");
printf(" 6 1 2\n");
printf(" 7 2 1\n");
printf(" 8 2 2\n");
printf(" # Generated by triangle -pcBev box\n");
printf("\n");
printf(" Here is the triangulation file, `box.1.ele'.\n");
printf("\n");
printf(" 8 3 0\n");
printf(" 1 1 5 6\n");
printf(" 2 5 1 3\n");
printf(" 3 2 6 8\n");
printf(" 4 6 2 1\n");
printf(" 5 7 3 4\n");
printf(" 6 3 7 5\n");
printf(" 7 8 4 2\n");
printf(" 8 4 8 7\n");
printf(" # Generated by triangle -pcBev box\n\n");
printf(" Here is the edge file for the triangulation, `box.1.edge'.\n\n");
printf(" 16 0\n");
printf(" 1 1 5\n");
printf(" 2 5 6\n");
printf(" 3 6 1\n");
printf(" 4 1 3\n");
printf(" 5 3 5\n");
printf(" 6 2 6\n");
printf(" 7 6 8\n");
printf(" 8 8 2\n");
printf(" 9 2 1\n");
printf(" 10 7 3\n");
printf(" 11 3 4\n");
printf(" 12 4 7\n");
printf(" 13 7 5\n");
printf(" 14 8 4\n");
printf(" 15 4 2\n");
printf(" 16 8 7\n");
printf(" # Generated by triangle -pcBev box\n");
printf("\n");
printf(
" Here's a file `box.1.part' that partitions the mesh into four subdomains.\n"
);
printf("\n");
printf(" 8 4\n");
printf(" 1 3\n");
printf(" 2 3\n");
printf(" 3 4\n");
printf(" 4 4\n");
printf(" 5 1\n");
printf(" 6 1\n");
printf(" 7 2\n");
printf(" 8 2\n");
printf(" # Generated by slice -s4 box.1\n\n");
printf(
" Here's a file `box.1.adj' that represents the resulting adjacencies.\n");
printf("\n");
printf(" 4\n");
printf(" 9\n");
printf(" 2\n");
printf(" 2\n");
printf(" 0\n");
printf(" 2\n");
printf(" 9\n");
printf(" 0\n");
printf(" 2\n");
printf(" 2\n");
printf(" 0\n");
printf(" 9\n");
printf(" 2\n");
printf(" 0\n");
printf(" 2\n");
printf(" 2\n");
printf(" 9\n");
printf("\n");
printf("Display Speed:\n");
printf("\n");
printf(
" It is worthwhile to note that .edge files typically plot and print twice\n"
);
printf(
" as quickly as .ele files, because .ele files cause each internal edge to\n"
);
printf(
" be drawn twice. For the same reason, PostScript files created from edge\n"
);
printf(" sets are smaller than those created from triangulations.\n\n");
printf("Show Me on the Web:\n\n");
printf(
" To see an illustrated, updated version of these instructions, check out\n");
printf("\n");
printf(" http://www.cs.cmu.edu/~quake/showme.html\n");
printf("\n");
printf("A Brief Plea:\n");
printf("\n");
printf(
" If you use Show Me (or Triangle), and especially if you use it to\n");
printf(
" accomplish real work, I would like very much to hear from you. A short\n");
printf(
" letter or email (to jrs@cs.cmu.edu) describing how you use Show Me (and\n");
printf(
" its sister programs) will mean a lot to me. The more people I know\n");
printf(
" are using my programs, the more easily I can justify spending time on\n");
printf(
" improvements, which in turn will benefit you. Also, I can put you\n");
printf(
" on a list to receive email whenever new versions are available.\n");
printf("\n");
printf(
" If you use a PostScript file generated by Show Me in a publication,\n");
printf(" please include an acknowledgment as well.\n\n");
exit(0);
}
void set_filenames(filename, lowermeshnumber)
char *filename;
int lowermeshnumber;
{
char numberstring[100];
int i;
for (i = 0; i < 2; i++) {
strcpy(nodefilename[i], filename);
strcpy(polyfilename[i], filename);
strcpy(elefilename[i], filename);
strcpy(edgefilename[i], filename);
strcpy(partfilename[i], filename);
strcpy(adjfilename[i], filename);
strcpy(vnodefilename[i], filename);
strcpy(vedgefilename[i], filename);
if (lowermeshnumber + i > 0) {
sprintf(numberstring, ".%d", lowermeshnumber + i);
strcat(nodefilename[i], numberstring);
strcat(polyfilename[i], numberstring);
strcat(elefilename[i], numberstring);
strcat(edgefilename[i], numberstring);
strcat(partfilename[i], numberstring);
strcat(adjfilename[i], numberstring);
strcat(vnodefilename[i], numberstring);
strcat(vedgefilename[i], numberstring);
}
strcat(nodefilename[i], ".node");
strcat(polyfilename[i], ".poly");
strcat(elefilename[i], ".ele");
strcat(edgefilename[i], ".edge");
strcat(partfilename[i], ".part");
strcat(adjfilename[i], ".adj");
strcat(vnodefilename[i], ".v.node");
strcat(vedgefilename[i], ".v.edge");
}
}
void parsecommandline(argc, argv)
int argc;
char **argv;
{
int increment;
int meshnumber;
int i, j;
quiet = 0;
fillelem = 0;
line_width = 1;
bw_ps = 0;
start_image = ELE;
filename[0] = '\0';
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
for (j = 1; argv[i][j] != '\0'; j++) {
if (argv[i][j] == 'f') {
fillelem = 1;
}
if (argv[i][j] == 'w') {
if ((argv[i][j + 1] >= '1') && (argv[i][j + 1] <= '9')) {
line_width = 0;
while ((argv[i][j + 1] >= '0') && (argv[i][j + 1] <= '9')) {
j++;
line_width = line_width * 10 + (int) (argv[i][j] - '0');
}
if (line_width > 100) {
printf("Error: Line width cannot exceed 100.\n");
line_width = 1;
}
}
}
if (argv[i][j] == 'b') {
bw_ps = 1;
}
if (argv[i][j] == 'Q') {
quiet = 1;
}
if ((argv[i][j] == 'h') || (argv[i][j] == 'H') ||
(argv[i][j] == '?')) {
info();
}
}
} else {
strcpy(filename, argv[i]);
}
}
if (filename[0] == '\0') {
syntax();
}
if (!strcmp(&filename[strlen(filename) - 5], ".node")) {
filename[strlen(filename) - 5] = '\0';
start_image = NODE;
}
if (!strcmp(&filename[strlen(filename) - 5], ".poly")) {
filename[strlen(filename) - 5] = '\0';
start_image = POLY;
}
if (!strcmp(&filename[strlen(filename) - 4], ".ele")) {
filename[strlen(filename) - 4] = '\0';
start_image = ELE;
}
if (!strcmp(&filename[strlen(filename) - 5], ".edge")) {
filename[strlen(filename) - 5] = '\0';
start_image = EDGE;
}
if (!strcmp(&filename[strlen(filename) - 5], ".part")) {
filename[strlen(filename) - 5] = '\0';
start_image = PART;
}
if (!strcmp(&filename[strlen(filename) - 4], ".adj")) {
filename[strlen(filename) - 4] = '\0';
start_image = ADJ;
}
increment = 0;
j = 1;
while (filename[j] != '\0') {
if ((filename[j] == '.') && (filename[j + 1] != '\0')) {
increment = j + 1;
}
j++;
}
meshnumber = 0;
if (increment > 0) {
j = increment;
do {
if ((filename[j] >= '0') && (filename[j] <= '9')) {
meshnumber = meshnumber * 10 + (int) (filename[j] - '0');
} else {
increment = 0;
}
j++;
} while (filename[j] != '\0');
}
if (increment > 0) {
filename[increment - 1] = '\0';
}
if (meshnumber == 0) {
start_inc = 0;
loweriteration = 0;
} else {
start_inc = 1;
loweriteration = meshnumber - 1;
}
set_filenames(filename, loweriteration);
}
void free_inc(inc)
int inc;
{
if (loaded[inc][NODE]) {
free(nodeptr[inc]);
}
if (loaded[inc][POLY]) {
if (polynodes[inc] > 0) {
free(polynodeptr[inc]);
}
free(polyedgeptr[inc]);
free(polyholeptr[inc]);
}
if (loaded[inc][ELE]) {
free(eleptr[inc]);
}
if (loaded[inc][PART]) {
free(partpart[inc]);
free(partcenter[inc]);
free(partshift[inc]);
}
if (loaded[inc][EDGE]) {
free(edgeptr[inc]);
free(normptr[inc]);
}
if (loaded[inc][ADJ]) {
free(adjptr[inc]);
}
if (loaded[inc][VORO]) {
free(vnodeptr[inc]);
free(vedgeptr[inc]);
free(vnormptr[inc]);
}
}
void move_inc(inc)
int inc;
{
int i;
free_inc(1 - inc);
for (i = 0; i < IMAGE_TYPES; i++) {
loaded[1 - inc][i] = loaded[inc][i];
loaded[inc][i] = 0;
xlo[1 - inc][i] = xlo[inc][i];
ylo[1 - inc][i] = ylo[inc][i];
xhi[1 - inc][i] = xhi[inc][i];
yhi[1 - inc][i] = yhi[inc][i];
}
nodes[1 - inc] = nodes[inc];
node_dim[1 - inc] = node_dim[inc];
nodeptr[1 - inc] = nodeptr[inc];
polynodes[1 - inc] = polynodes[inc];
poly_dim[1 - inc] = poly_dim[inc];
polyedges[1 - inc] = polyedges[inc];
polyholes[1 - inc] = polyholes[inc];
polynodeptr[1 - inc] = polynodeptr[inc];
polyedgeptr[1 - inc] = polyedgeptr[inc];
polyholeptr[1 - inc] = polyholeptr[inc];
elems[1 - inc] = elems[inc];
ele_corners[1 - inc] = ele_corners[inc];
eleptr[1 - inc] = eleptr[inc];
edges[1 - inc] = edges[inc];
edgeptr[1 - inc] = edgeptr[inc];
normptr[1 - inc] = normptr[inc];
subdomains[1 - inc] = subdomains[inc];
partpart[1 - inc] = partpart[inc];
partcenter[1 - inc] = partcenter[inc];
partshift[1 - inc] = partshift[inc];
adjsubdomains[1 - inc] = adjsubdomains[inc];
adjptr[1 - inc] = adjptr[inc];
vnodes[1 - inc] = vnodes[inc];
vnode_dim[1 - inc] = vnode_dim[inc];
vnodeptr[1 - inc] = vnodeptr[inc];
vedges[1 - inc] = vedges[inc];
vedgeptr[1 - inc] = vedgeptr[inc];
vnormptr[1 - inc] = vnormptr[inc];
firstnumber[1 - inc] = firstnumber[inc];
firstnumber[inc] = -1;
}
void unload_inc(inc)
int inc;
{
int i;
current_image = NOTHING;
for (i = 0; i < IMAGE_TYPES; i++) {
loaded[inc][i] = 0;
firstnumber[inc] = -1;
}
}
void showme_init()
{
current_image = NOTHING;
current_inc = 0;
explosion = STARTEXPLOSION;
unload_inc(0);
unload_inc(1);
}
char *readline(string, infile, infilename)
char *string;
FILE *infile;