home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / vplot / part17 < prev    next >
Encoding:
Internet Message Format  |  1988-03-31  |  49.4 KB

  1. Subject:  v14i022:  Device-independant graphics system, with drivers
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Joe Dellinger <joe@hanauma.STANFORD.EDU>
  7. Posting-number: Volume 14, Issue 22
  8. Archive-name: vplot/part17
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 17 (of 24)."
  17. # Wrapped by rsalz@fig.bbn.com on Fri Mar 25 11:47:28 1988
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'Vplot_Kernel/Documentation/vplottext.mn' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'Vplot_Kernel/Documentation/vplottext.mn'\"
  21. else
  22. echo shar: Extracting \"'Vplot_Kernel/Documentation/vplottext.mn'\" \(15800 characters\)
  23. sed "s/^X//" >'Vplot_Kernel/Documentation/vplottext.mn' <<'END_OF_FILE'
  24. X.TH vplot_text 9 "7 April 1987"
  25. X.SH NAME
  26. vplot text \- A guide to using the new Hershey fonts in vplot
  27. X
  28. X.SH DESCRIPTION
  29. Vplot fonts are mixtures of vectors and filled areas which simulate typeset
  30. fonts on graphics devices.  Since they are not raster, they can be arbitrarily
  31. scaled, stretched, skewed, and rotated, and can be plotted on any device.
  32. X
  33. There are 17 fonts.  Font 0 is just the regular old PEN font we've been using all
  34. along.  The default font is device and installation dependent, or can be set
  35. from the command line (see options below).
  36. Here is a complete list of fonts and their number:
  37. X
  38. X.br
  39. X0 pen
  40. X.br
  41. X1 roman simplex
  42. X.br
  43. X2 roman duplex
  44. X.br
  45. X3 roman complex
  46. X.br
  47. X4 roman triplex
  48. X.br
  49. X5 italic complex
  50. X.br
  51. X6 italic triplex
  52. X.br
  53. X7 script simplex
  54. X.br
  55. X8 script complex
  56. X.br
  57. X9 greek simplex
  58. X.br
  59. X10 greek complex
  60. X.br
  61. X11 Cyrillic complex
  62. X.br
  63. X12 German style gothic triplex
  64. X.br
  65. X13 Greek style gothic triplex
  66. X.br
  67. X14 Italian style gothic triplex
  68. X.br
  69. X15 mathematics
  70. X.br
  71. X16 miscellaneous
  72. X.br
  73. X
  74. Font 0 was designed by Rob Clayton at Stanford.  Fonts 1 through 16 are debugged
  75. versions of the `Hershey' fonts available from mod.sources.  In order to
  76. have permission to use these fonts, I must now display this message:
  77. X
  78. X.br
  79. X    - The Hershey Fonts were originally created by Dr.
  80. X.br
  81. X        A. V. Hershey while working at the U. S.
  82. X.br
  83. X        National Bureau of Standards.
  84. X
  85. X.SH INTERFACE
  86. This section describes the control sequences which are accessible to any user
  87. of
  88. X.B vplot
  89. text, via whatever program.
  90. X
  91. Vplot text recognizes `\\' as a special character used to signal the start of
  92. an escape sequence.  There are two sorts of escape sequences, those that take an
  93. argument and those that do not.
  94. X
  95. Here is a complete list of escape sequences that do not take an argument:
  96. X.br
  97. X\\>    Advance one interletter space
  98. X.br
  99. X\\<    Back up one interletter space
  100. X.br
  101. X\\^    Raise one half of a capital letter height
  102. X.br
  103. X\\_    Lower one half of a capital letter height
  104. X.br
  105. X\\g    Continue processing text, but don't actually print it (`ghostify it').
  106. This is useful if you want to leave space to go back and add something by hand.
  107. X.br
  108. X\\G    Start printing text again
  109. X.br
  110. X\\n    Newline
  111. X.br
  112. X\\h    Backspace (control-h also works) back up over the last character
  113. X.br
  114. X\\-    Does nothing; used to prevent a group of characters from being formed
  115. into a ligature.
  116. X.br
  117. X\\\\    Print a backslash
  118. X.br
  119. X
  120. The following take an integer argument immediately after, with a
  121. X.B required space
  122. after the integer to delineate the end.  This space is not printed.
  123. X
  124. X.br
  125. X\\s    Size change.  Change to this percent of the size set in the text vplot
  126. call.  \\s100  restores the default height.
  127. X.br
  128. X\\f    Add this to current fatness.  Goes out of effect when text printing is
  129. finished.
  130. X.br
  131. X\\F    Switch to this font number.  (-1 restores the default font).
  132. X.br
  133. X\\k    Move by this many space widths to the right.
  134. X.br
  135. X\\r    Move up this many character heights (the height of a standard capital
  136. letter, such as `A').
  137. X.br
  138. X\\v    Print this ASCII character number in the current font, stripping it
  139. of any special meaning.
  140. This and ligatures are the only way that glyphs numbered
  141. greater than 255 are available.
  142. X.br
  143. X\\c    Switch to this color.  -1 restores the current drawing color.
  144. Vplot's current drawing color is not changed by changing the color inside text.
  145. X.br
  146. X\\m    Save current position in this number register.
  147. X.br
  148. X\\M    Restore position saved in this number register.
  149. X.br
  150. X
  151. X.SH EXAMPLES
  152. Since programs such as `graph' do not interpret text themselves, but
  153. rely on vplot to do it, the above control sequences may simply be used wherever
  154. any graphics text is used.  For example, instead of specifying as an option to
  155. graph label=`beta', you can specify label=`\\F9 b' and actually get the Greek
  156. letter beta from the Greek Simplex font.
  157. X
  158. X    Here are some more examples:
  159. X
  160. X    To get an integral sign:
  161. X.br
  162. X    \\F15 \\v168 
  163. X.br
  164. X    Translation: Switch to font 15 (math symbols), print character #168 (integral
  165. sign).
  166. X
  167. X    To get `X squared plus Y squared':
  168. X.br
  169. X    X\\^2\\_ + Y\\^2
  170. X.br
  171. X    Translation: Print X, go up half, print 2, go back down half, print +,
  172. print Y, go up half, print 2.
  173. X
  174. X    As an advanced example, to get `A sub b sup beta':
  175. X.br
  176. X    A\\m1 \\_b\\M1 \\^\\F9 b
  177. X.br
  178. X    Translation: Do A, save this spot, go down half, do b, restore the
  179. saved spot, go up half, switch to font 9 (Greek Simplex) do beta.  (Notice
  180. the use of marks to stack characters on top of each other.)
  181. X
  182. X    Warning: \\ is a special character in C.  To get a backslash, you
  183. have to use \\\\.
  184. X
  185. X.SH GENERIC PEN OPTIONS
  186. X
  187. X.TP
  188. X.B txfont=font_number
  189. Txfont specifies the default text font.
  190. The default is device and installation
  191. dependent.  Generally, screen devices will default to the `pen' font since it is
  192. by far the fastest to draw, and hardcopy devices will default to either
  193. roman simplex
  194. or roman complex since these are the closest to looking like standard typeset
  195. text.  Out-of-range font
  196. numbers (starting at 100) may be used in a device-dependent fashion
  197. to access hardware fonts on devices that have them. Devices that don't have
  198. hardware fonts will use the font number modulo 100.
  199. Fonts 0-99 are guaranteed device-independent.
  200. X
  201. X.TP
  202. X.B txprec=0
  203. Txprec specifies the default text precision (a GKS term).
  204. Possible values are character (0), string (1), and stroke (2).
  205. For vector fonts, the text precision parameter is ignored except that
  206. ligatures are only enabled at precision 2.  The precision parameter
  207. may be significant if device-dependent hardware fonts are used,
  208. however.  The default precision is device and installation dependent.
  209. X
  210. X.TP
  211. X.B txovly=0
  212. Txovly sets the default text overlay mode.
  213. This controls whether or not to clear out an area behind the
  214. text before writing it, and whether or not to put a box around it.
  215. Overlay modes 1 and 3 draw a box, and modes 2 and 3 shade the inside of
  216. the box with the background color.  The default text overlay mode is 0
  217. X(do nothing).
  218. All text overlay modes may not be supported on all devices.
  219. X(Some devices cannot shade to background color, for example.)
  220. X
  221. The default font, default precision, and default text overlay mode may all be
  222. reset by the appropriate vplot command.
  223. X
  224. X.TP
  225. X.B fontN=file_name
  226. The binary format vplot font file for font number N is located in file_name.
  227. If the font number is not one normally defined on the system, file_name
  228. defaults to fontN, where again N is the font number. If the device does
  229. not have hardware fonts, the font number modulo 100 will be used
  230. for all internal purposes (so fonts 201 and 101 must be the same,
  231. for example). The N in the above option will still be the
  232. original font number, however. Fonts that are included
  233. at compile time are hardwired and cannot be changed.
  234. X
  235. X.SH LIGATURES
  236. Fonts may specify that certain combinations of adjacent glyphs be combined into
  237. a single new glyph whenever they occur.  For example, `ffi' in font 3 (it's
  238. a ligature in troff, too).  This
  239. takes place automatically at precision 2.
  240. The only fonts which currently contain
  241. ligatures are the Roman Complex, Italic Complex, and Cyrillic Complex fonts.
  242. X(Ligatures may be used in fonts for foreign languages to good effect to
  243. automatically de-transliterate English approximations.  For example, `sh' in
  244. the Cyrillic font automatically comes out as a single Shah character.
  245. X`KHrushchev', for example, contains only 6 glyphs: KH-r-u-shch-e-v.
  246. The K and H here are both
  247. capitalized since they are both part of the first character.  The `Tests'
  248. directory contains the example TEST_Cyrillic which shows how to generate
  249. every letter in the Cyrillic alphabet.)
  250. X
  251. X.SH TEXT JUSTIFICATION
  252. Text justification is set by the appropriate command in vplot, and follows
  253. the GKS standard.
  254. Since this text routine allows character size and active font to
  255. be changed within a single text string, the GKS standard is extended so that
  256. X`TOP' and `BOTTOM' alignments align on the highest top and the lowest
  257. bottom of the characters used.  (Note that this makes the alignment font and
  258. size dependent, but not dependent on the actual characters used.)
  259. The `CAP' and `HALF' alignments are determined
  260. by those for the default font.
  261. X
  262. All sizes of all fonts are aligned together by their baselines.
  263. X
  264. Horizontal alignment is based according to the beginning and ending horizontal
  265. positions.  You can use marks to make the ending position be anywhere in the
  266. string you wish.
  267. X
  268. A `SYMBOL' justification mode has also been added to those defined by GKS.
  269. Each glyph has a `hot
  270. spot' defined, which is where the glyph is to be centered if it is used as
  271. a symbol.  The last printable character in a string is the character centered on
  272. as the symbol.  To center on a character in the middle
  273. of the string as a symbol, mark the spot with the \\m command immediately after that
  274. character and then restore that location at the end of the string with the
  275. X\\M command.  That character
  276. is now the `last character' as far as all centering is concerned.
  277. Size changes and horizontal
  278. shifts are taken into account
  279. in the symbol justification mode, but shifts up and down are not.
  280. X
  281. Vplot polymarkers are drawn by setting the SYMBOL text justification mode,
  282. setting the correct font,
  283. creating a special single-character string, and
  284. then calling the text routine to draw the symbol.
  285. X
  286. X.SH DIAGNOSTICS
  287. Nonexistent glyphs are rendered as a special `error' glyph.  Which glyph is
  288. used for this is installation dependent, and is set by defines in
  289. gentext.c.  As distributed, it is glyph 30 in font 0, which is a `?' inside
  290. a diamond.  (I stole this idea from the Imagen laser printer.)  An error message
  291. will be produced the first time that a nonexistent glyph is referenced.
  292. X(Only the first time so that you don't get overwhelmed with error messages
  293. if you're trying to use a font that doesn't exist on that system.)
  294. Attempts to use nonexistent fonts produce
  295. an error message and font 0 (or whatever other font has been
  296. designated as the error font in gentext.c) is used instead.
  297. X
  298. Various other non-fatal errors can occur and all
  299. give self-explanatory error messages.
  300. X
  301. X.SH COPYRIGHT
  302. The Vplot source code is copyrighted. Please read the copyright notice you
  303. will find in the Vplot manual page.
  304. X
  305. X.SH FONT FILES
  306. Font files used by the vplot text subroutine `gentext' are kept in
  307. X.../vplot/filters/include/vplotfonts/*.  There are two forms for each font,
  308. an `include' form and a `binary' form.  The include form is compiled in
  309. as an #include file into gentext.  This is more efficient, but makes the
  310. executable code considerably longer and slows down compilation.
  311. The binary form is loaded on the fly as
  312. needed at runtime.  Which method is used for which font is system dependent
  313. and is determined by the file .../vplot/include/font_definitions.h.
  314. X
  315. X.SH ASSOCIATED PROGRAMS
  316. The subroutine
  317. X.B gentext.c
  318. is the device-independent generic subroutine that vplot uses to draw
  319. vector fonts.
  320. Gentext.c is constructed in such a way that it could easily be fit into a GKS
  321. package.  While Vplot itself thinks in terms of `text orientation' and
  322. X`text size', gentext thinks in terms of `character up vectors' and
  323. X`character path vectors'.  Squashed, slanted, etc, text can be produced
  324. by having these two vectors not be perpendicular or not the same length.
  325. X(This can only happen when using vplot when xscale does not equal yscale.)
  326. X
  327. The program
  328. X.B makefont.c
  329. takes a `vplot font' and encodes it into the forms required by gentext.
  330. The format of a `vplot font' is designed such that it can be read into the
  331. program `plas'
  332. and then piped into a vplot filter.  IE, the command
  333. X.br
  334. plas < cyrilc.vplot_font | ?pen xcenter=0 ycenter=0 scale=50 pause=1
  335. X.br
  336. will display each glyph in the cyrillic font, one per second.
  337. X
  338. The exact format of a `vplot font' file is given in comments at the beginning of
  339. makefont.c, and the file pen.vplot_font serves as an example.
  340. Since vplot_fonts are just open-format vplot files, it is very easy to create your
  341. own special purpose glyphs, markers, or fonts and add these to the system.
  342. X
  343. The program
  344. X.B hertovplot.c
  345. converts `Hershey' font data as distributed by mod.sources
  346. X(mod.sources is a UNIX network `news' group for distributing
  347. useful UNIX software.)
  348. into vplot fonts.
  349. Its use is described in comments at the beginning of the program.
  350. The program
  351. X.B hertogrid.c
  352. draws all the glyphs in a Hershey glyph file on a grid, labeling each glyph
  353. with its number.  (The Hershey glyph files have to be organized into reasonable
  354. fonts by hand! The organization of my fonts mostly follows those provided by
  355. Mr. Hurt, but I have added in a few things he missed
  356. and reordered the non-English
  357. fonts to make more sense.  I have stolen bits of Mr. Hurt's code to write
  358. hertovplot.c and hertogrid.c.)
  359. X
  360. X.SH FONT INSTALLATION
  361. To install all the fonts, you must first obtain the Hershey fonts for
  362. yourself
  363. as distributed by mod.sources (if you don't know how to get stuff
  364. from them, then how did you get this file that you're reading now?).
  365. Follow the instructions to create the
  366. four `.oc' files, and copy these into the .../vplot/Hershey directory.
  367. Do not copy the `.hmp' files.
  368. Follow the instructions you will find in the file .../vplot/Hershey/README
  369. to make all the required `vplot_font's.
  370. X(Note that pen.vplot_font is not part of the Hershey font distribution.
  371. This font was created by Rob Clayton around 1980, and slightly modified
  372. by Joe Dellinger in 1986.)
  373. Once you have done this,
  374. go into the .../vplot/filters/include/vplotfonts directory, and
  375. do `make'.  This will create the required `.include' and `.bin'
  376. fonts.
  377. X
  378. X.SH SEE ALSO
  379. pen(9) vplot(9) libvplot(9)
  380. X
  381. X.SH AUTHOR
  382. Joe Dellinger
  383. X(joe@hanauma.stanford.edu, convex!convexw!hanauma!joe, decvax!hanauma!joe)
  384. You may ask me for advice if you wish to help do any of the things in
  385. the wish list below.
  386. X
  387. X.SH BUGS
  388. The letter `J' in the Roman Triplex font in the Hershey font distribution
  389. has mangled width information.  The vplot font for this font has to be edited by
  390. hand to correct this mistake.
  391. X
  392. Gentext.c does not yet support all the required GKS features.  However, as all
  393. the internal calculations are done in a way consistent with the GKS model
  394. modifying the code to support these is a very straightforward job which I
  395. leave to someone else.
  396. X
  397. Somebody should make sure that all the `hot spots' defined for characters
  398. are reasonable.  (The `hot spot' is the point that is aligned on when
  399. symbol alignment mode is used.)
  400. X(The ones installed now are the defaults chosen by
  401. makefont.c.)  Somebody should create a special `polymarker' font.
  402. Currently several of the more esoteric symbols called by the vplot
  403. polymarker command are not very well centered (notably triangles).
  404. X
  405. Somebody should write an interactive program to create new glyphs with.
  406. X
  407. Somebody should turn some of the better Hershey vector fonts into filled-area
  408. fonts.  (Unfortunately, Mr. Hershey didn't see fit to order his vectors in such
  409. a way as to make this easy.) The only thing lacking is the font itself,
  410. because vplot itself already supports arbitrary mixtures of filled-areas
  411. and vectors in fonts.  Currently there are just a few glyphs containing
  412. filled areas in font 0, as examples showing how to do it.
  413. X
  414. Dr. Geller (the first tenured American professor at a Japanese university,
  415. and a former Stanford Earth Sciences professor)
  416. should have his students create a katakana and a hirigana font.
  417. Ligatures can be used to pair the appropriate consonant-vowel pairs.
  418. There are also quite a few Kanji glyphs available as well, from which a Kanji
  419. font could be constructed.
  420. A ligature could be constructed to turn each English word into its Kanji
  421. equivalent! (The number of glyphs in a font is not limited to 256! That's
  422. why I did things that way.)
  423. X
  424. Somebody should extend the way ligatures are read from vplot font files,
  425. so that you can just give the
  426. ASCII character itself instead of the glyph number
  427. if one exists.  Since I only had a few ligatures I didn't want to bother with
  428. this.
  429. END_OF_FILE
  430. if test 15800 -ne `wc -c <'Vplot_Kernel/Documentation/vplottext.mn'`; then
  431.     echo shar: \"'Vplot_Kernel/Documentation/vplottext.mn'\" unpacked with wrong size!
  432. fi
  433. # end of 'Vplot_Kernel/Documentation/vplottext.mn'
  434. fi
  435. if test -f 'Vplot_Kernel/filters/genlib/polyfix.c' -a "${1}" != "-c" ; then 
  436.   echo shar: Will not clobber existing file \"'Vplot_Kernel/filters/genlib/polyfix.c'\"
  437. else
  438. echo shar: Extracting \"'Vplot_Kernel/filters/genlib/polyfix.c'\" \(15037 characters\)
  439. sed "s/^X//" >'Vplot_Kernel/filters/genlib/polyfix.c' <<'END_OF_FILE'
  440. X/*
  441. X * Copyright 1987 the Board of Trustees of the Leland Stanford Junior
  442. X * University. Official permission to use this software is included in
  443. X * the documentation. It authorizes you to use this file for any
  444. X * non-commercial purpose, provided that this copyright notice is not
  445. X * removed and that any modifications made to this file are commented
  446. X * and dated in the style of my example below.
  447. X */
  448. X
  449. X/*
  450. X *
  451. X *  source file:   ./filters/genlib/polyfix.c
  452. X *
  453. X * Joe Dellinger (SEP), June 11 1987
  454. X *    Inserted this sample edit history entry.
  455. X *    Please log any further modifications made to this file:
  456. X * Joe Dellinger Feb 29, 1988
  457. X *    Changed POLYS to 5000 so it will compile on RT's.
  458. X *    Somebody should change the whole thing into linked lists!
  459. X */
  460. X
  461. X#include <stdio.h>
  462. X#include "../include/err.h"
  463. X#include "../include/extern.h"
  464. X#include "../include/params.h"
  465. X#define EMPTY -100
  466. X#define NOLINK -10
  467. X#define ENDOFLIST -1
  468. X#define UNCLAIMED 0
  469. X#define CLAIMED 1
  470. X#define INTERIOR 0
  471. X#define POLYS   5000    /* Memory alloted for polygon */
  472. X#define MAXPOL  500    /* Maximum number of polygons made */
  473. X
  474. X/*
  475. X * This routine breaks up the clipped polygon generated by "polygon" into
  476. X * multiple polygons as needed, using the Thorson-Dellinger method!
  477. X *
  478. X *    Note 1:
  479. X *    The output of "polygon" is a clipped polygon with different parts
  480. X *    joined by lines around the edge of the window. (This is unsightly.)
  481. X *    This routine seems to do a reasonably efficient job of fixing this.
  482. X *    (It's a pretty hard problem!)
  483. X *
  484. X *    Note 2:
  485. X *    This always (I hope) works for non-crossed polygons. Crossed polygons
  486. X *    will sometimes be turned into two overlapping polygons,
  487. X *    which can cause interior voids to be shaded. Some terminals,
  488. X *    like the color tektronix, can be sent multiple polygons
  489. X *    and told that they are to be shaded as one. If this is the
  490. X *    case, the routine should always (I think) work, even for crossed
  491. X *    polygons. To fix this problem, you would have to laboriously
  492. X *    look for intersections of "disjoint" polygons. A new point would
  493. X *    then be added at the intersection, and the two polygons joined
  494. X *    into one through that point. The required routines are pretty much
  495. X *    already in this program, but it seems that the large amount of
  496. X *    time to check for this obscure case is not worth it. There seems
  497. X *    to be no obvious way around this.
  498. X *
  499. X *        --- Joe Dellinger, May 7, 1984.
  500. X *
  501. X *    Looking back on this I realize that I still had a lot to learn
  502. X *    about C coding when I wrote this; some kind soul should go back
  503. X *    and update this to use pointers and allocated linked-lists.
  504. X *    I don't feel like doing this myself; the thing works perfectly
  505. X *    for us even if the code itself is a mess!
  506. X *
  507. X *        --- Joe Dellinger, May 3, 1987.
  508. X */
  509. X
  510. static int      poly[POLYS][5];
  511. X/*
  512. X * Doubly linked list that will contain the vertices of our polygons. 0-X 1-Y
  513. X * 2-forward link 3-backward link 4-which edge? 1-bottom 2-left 4-top 8-right 
  514. X */
  515. static int      pols[MAXPOL];    /* Point to the start of each polygon */
  516. static int      polsc[MAXPOL];    /* Cycle length */
  517. static int      npols;    /* How many polygons we have */
  518. X
  519. static int      pedge[POLYS];    /* Edge points of the polygon */
  520. static int      nedge, nedge2;    /* number of edge points */
  521. X
  522. static int      point, endlist;
  523. X
  524. int             bottom, left;
  525. X
  526. X
  527. int             Allgone;/* Communicate to polygon whether we ever got
  528. X             * anything */
  529. X
  530. polyfix (x, y, first)    /* Read in the data for polystart */
  531. X    int             x, y, *first;
  532. X{
  533. static int      oldx, oldy;
  534. X
  535. X    if (*first == 1)
  536. X    {
  537. X    *first = 0;
  538. X    point = 1;
  539. X    Allgone = 0;        /* All the points aren't gone! */
  540. X    oldx = x + 1;
  541. X    oldy = y + 1;        /* Won't match */
  542. X    }
  543. X    /*
  544. X     * Put the point x,y into the list as number point, Unless it is *
  545. X     * superfluous 
  546. X     */
  547. X    if ((x == oldx) && (y == oldy))
  548. X    return;            /* ignore repeated points */
  549. X    poly[point][0] = x;        /* X of vertex */
  550. X    poly[point][1] = y;        /* Y of vertex */
  551. X    oldx = x;
  552. X    oldy = y;
  553. X    point++;
  554. X    if (point >= POLYS)
  555. X    ERR (FATAL, name, "Not enough memory for polygon!");
  556. X}
  557. X
  558. polystart ()        /* Start working on the polygons */
  559. X{
  560. int             i, j, k, l, ii;
  561. int             firstpoint, flag, double_check;
  562. int             temp1, temp2, temp;
  563. extern int      smart_clip;
  564. X
  565. X    endlist = point;        /* Last element in use */
  566. X    /* initialize array */
  567. X    for (i = 0; i <= point; i++)
  568. X    {
  569. X    poly[i][4] = INTERIOR;
  570. X    poly[i][2] = i + 1;
  571. X    poly[i][3] = i - 1;
  572. X    }
  573. X    poly[0][0] = poly[0][1] = EMPTY;
  574. X    poly[point][0] = poly[point][1] = EMPTY;
  575. X
  576. X    /* fix links of free list and last point */
  577. X    poly[0][3] = NOLINK;
  578. X    poly[0][2] = point;
  579. X    poly[point][2] = ENDOFLIST;
  580. X    poly[point][3] = 0;        /* point to start of free list */
  581. X
  582. X    poly[point - 1][2] = 1;    /* point to start of polygon */
  583. X    poly[1][3] = point - 1;
  584. X
  585. X    /* Now we have our polygon stored as a circular double-linked list! */
  586. X
  587. X    if (smart_clip)
  588. X    goto skip_it;        /* smart device can handle it from here */
  589. X
  590. X
  591. X    /* Identify all edge points */
  592. X
  593. X    /*
  594. X     * They are identified 2 ways; each point contains the information
  595. X     * itself, and there is an array which points to all edge points. This is
  596. X     * to avoid searching through the entire polygon. 
  597. X     */
  598. X
  599. X    nedge = 0;
  600. X    i = firstpoint = 1;        /* Since we are just starting, we know the
  601. X                 * polygon MUST start here */
  602. X    do
  603. X    {
  604. X    if (poly[i][4] = edge (poly[i][0], poly[i][1]))    /* NOT an == */
  605. X    {
  606. X        /* It's on an edge */
  607. X        nedge++;
  608. X        pedge[nedge] = i;
  609. X    }
  610. X    i = poly[i][2];
  611. X    }
  612. X    while (firstpoint != i);
  613. X
  614. X    nedge2 = nedge;
  615. X
  616. X    /*
  617. X     * Look at each edge segment. See if any edge points occur inside
  618. X     * segments joining two other edge points. (Got that?) 
  619. X     */
  620. X
  621. X    for (ii = 1; ii <= nedge2; ii++)
  622. X    {
  623. X    i = pedge[ii];
  624. X    if (k = (poly[i][4] & poly[poly[i][2]][4]))
  625. X    {
  626. X        /* We have an edge link. That is, it connects to edge vertices. */
  627. X        /* See if any other edge points lie inbetween these two. */
  628. X        for (j = 1; j <= nedge; j++)
  629. X        {
  630. X        if (k & poly[pedge[j]][4])
  631. X        {
  632. X            /* This point is on the correct edge */
  633. X
  634. X            l = ((k & (8 + 2)) > 0);
  635. X
  636. X            /* l = 0 if top or bottom, 1 if left or right */
  637. X
  638. X            if (poly[i][l] > poly[poly[i][2]][l])
  639. X            {
  640. X            if ((poly[pedge[j]][l] > poly[poly[i][2]][l])
  641. X                && (poly[pedge[j]][l] < poly[i][l]))
  642. X                /* Got one! */
  643. X                /* insert it into the list */
  644. X            {
  645. X                nedge2++;
  646. X                insert (i, poly[pedge[j]][0],
  647. X                    poly[pedge[j]][1],
  648. X                    poly[pedge[j]][4]);
  649. X                pedge[nedge2] = poly[i][2];
  650. X            }
  651. X            }
  652. X            else
  653. X            {
  654. X            if ((poly[pedge[j]][l] < poly[poly[i][2]][l])
  655. X                && (poly[pedge[j]][l] > poly[i][l]))
  656. X                /* Got one! */
  657. X                /* insert it into the list */
  658. X            {
  659. X                nedge2++;
  660. X                insert (i, poly[pedge[j]][0],
  661. X                    poly[pedge[j]][1],
  662. X                    poly[pedge[j]][4]);
  663. X                pedge[nedge2] = poly[i][2];
  664. X            }
  665. X            }
  666. X        }
  667. X        /*
  668. X         * Whether you found one or not, continue on. If we did
  669. X         * insert one, IT is now the next point and our interval has
  670. X         * gotten shorter. Some sort of sorting would be more
  671. X         * effecient, but it doesn't seem worth the extra complexity
  672. X         * at this time of night. It would involve a lot of special
  673. X         * cases, whereas doing it this way doesn't. 
  674. X         */
  675. X        }
  676. X    }
  677. X    }
  678. X
  679. X    nedge = nedge2;        /* Keep track of all the new edge points we
  680. X                 * just created */
  681. X
  682. X    /*
  683. X     * We have now inserted all the required points. Look for links that
  684. X     * connect the same two positions. (But different vertices... That is,
  685. X     * vertices which are not consecutive but have the same location!) 
  686. X     */
  687. X    /* Be careful that the link is not of zero length! */
  688. X    /*
  689. X     * Despite everything, it still seems to occasionally miss a spot. So as
  690. X     * an easy fix make it go through the search until it doesn't find
  691. X     * anything. In the overwhelming majority of cases, the first pass will
  692. X     * have done the job. 
  693. X     */
  694. X    double_check = 1;
  695. X    while (double_check == 1)
  696. X    {
  697. X    double_check = 0;
  698. X
  699. X    for (j = 1; j <= nedge; j++)    /* Loop through all edge points */
  700. X    {
  701. X        flag = 1;
  702. X        while (flag == 1)
  703. X        {
  704. X        flag = 0;
  705. X        if ((poly[pedge[j]][4] & poly[poly[pedge[j]][2]][4])
  706. X            && ((poly[pedge[j]][0] != poly[poly[pedge[j]][2]][0])
  707. X              || (poly[pedge[j]][1] != poly[poly[pedge[j]][2]][1])))
  708. X        {
  709. X            /*
  710. X             * This edge point's succesor is a point on the same
  711. X             * edge, And the link is not of zero length 
  712. X             */
  713. X            for (k = j; k <= nedge; k++)    /* Loop through edge
  714. X                             * points */
  715. X            {
  716. X            /* Look for a vertex that is at the same position */
  717. X            if ((poly[pedge[j]][0] == poly[pedge[k]][0])
  718. X                && (poly[pedge[j]][1] == poly[pedge[k]][1]))
  719. X            {
  720. X                /*
  721. X                 * OK, it is in the same position. See if either
  722. X                 * its succesor or predecessor is the same as the
  723. X                 * other end of the link. 
  724. X                 */
  725. X                if ((poly[poly[pedge[j]][2]][0] ==
  726. X                 poly[poly[pedge[k]][3]][0])
  727. X                && (poly[poly[pedge[j]][2]][1] ==
  728. X                    poly[poly[pedge[k]][3]][1]))
  729. X                {
  730. X                /*
  731. X                 * links go in opposite directions. (The easy
  732. X                 * case) Break the links and instead link
  733. X                 * points at the same location. Delete
  734. X                 * duplicated point. 
  735. X                 */
  736. X                /*
  737. X                 * pedge[j] and pedge[k] are at the same
  738. X                 * spot, as are pedge[j]'s succesor and
  739. X                 * pedge[k]'s predecessor. 
  740. X                 */
  741. X                temp1 = poly[pedge[j]][2];
  742. X                /* remember pedge[j]'s succesor */
  743. X                poly[pedge[j]][2] = pedge[k];
  744. X                /* pedge[j]'s succesor is now pedge[k] */
  745. X                temp2 = poly[pedge[k]][3];
  746. X                /* remember pedge[k]'s predecessor */
  747. X                poly[pedge[k]][3] = pedge[j];
  748. X                /*
  749. X                 * pedge[j] and pedge[k] are now linked. Link
  750. X                 * temp1 and temp2 
  751. X                 */
  752. X                poly[temp1][3] = temp2;
  753. X                poly[temp2][2] = temp1;
  754. X                /*
  755. X                 * Done. We have just split one polygon into
  756. X                 * two! 
  757. X                 */
  758. X                /* Clean up by removing the repeated vertices */
  759. X                delete (pedge[k]);
  760. X                pedge[k] = 0;
  761. X                /*
  762. X                 * Point this to a place we know is marked as
  763. X                 * an interior point. Always fails checks to
  764. X                 * see if it is on the edge we want. 
  765. X                 */
  766. X                delete (temp2);
  767. X                flag = 1;
  768. X                double_check = 1;
  769. X                }
  770. X                else
  771. X                {
  772. X                if ((j != k) &&
  773. X                    (poly[poly[pedge[j]][2]][0] ==
  774. X                     poly[poly[pedge[k]][2]][0])
  775. X                    && (poly[poly[pedge[j]][2]][1] ==
  776. X                    poly[poly[pedge[k]][2]][1]))
  777. X                {
  778. X                    /*
  779. X                     * the hard case. Both links go the same
  780. X                     * direction. Do as before, but Reverse
  781. X                     * the direction of one of the two
  782. X                     * pieces. 
  783. X                     */
  784. X                    temp1 = poly[pedge[j]][2];
  785. X                    temp2 = poly[pedge[k]][2];
  786. X                    i = temp1;
  787. X                    do
  788. X                    {    /* Reverse one piece first */
  789. X                    temp = poly[i][2];
  790. X                    poly[i][2] = poly[i][3];
  791. X                    poly[i][3] = temp;
  792. X                    i = temp;
  793. X                    }
  794. X                    while ((temp2 != i) && (temp1 != i));
  795. X                    poly[temp1][2] = temp2;
  796. X                    poly[temp2][3] = temp1;
  797. X                    if (i == temp2)
  798. X                    {
  799. X                    poly[pedge[j]][2] = pedge[k];
  800. X                    poly[pedge[k]][3] = pedge[j];
  801. X                    /*
  802. X                     * We have not created a new polygon,
  803. X                     * merely re-ordered one! 
  804. X                     */
  805. X                    }
  806. X                    else
  807. X                    {
  808. X                    poly[pedge[j]][3] = pedge[k];
  809. X                    poly[pedge[k]][2] = pedge[j];
  810. X                    /*
  811. X                     * We have merged two polygons back
  812. X                     * into one! 
  813. X                     */
  814. X                    }
  815. X                    /* clean up */
  816. X                    delete (pedge[k]);
  817. X                    pedge[k] = 0;
  818. X                    delete (temp2);
  819. X                    flag = 1;
  820. X                    double_check = 1;
  821. X                }
  822. X                }
  823. X            }
  824. X            if (flag == 1)
  825. X                break;
  826. X            /*
  827. X             * We've just altered the point we're at! So better
  828. X             * stop this loop. 
  829. X             */
  830. X            }        /* End of search loop */
  831. X        }
  832. X        }
  833. X    }
  834. X    }
  835. X
  836. X    /*
  837. X     * Our polygon has been fragmented into multiple smaller polygons as
  838. X     * necessary! Output the resulting polygons 
  839. X     */
  840. X
  841. skip_it:
  842. X    scan ();
  843. X
  844. X    for (i = 1; i <= npols; i++)
  845. X    {
  846. X    dev.startpoly (polsc[i]);
  847. X    j = pols[i];
  848. X    do
  849. X    {
  850. X        dev.midpoly (poly[j][0], poly[j][1]);
  851. X        j = poly[j][2];
  852. X    }
  853. X    while (j != pols[i]);
  854. X    dev.endpoly (i == npols);
  855. X    }
  856. X}
  857. X
  858. insert (where, x, y, z)
  859. X    int             where, x, y, z;
  860. X{
  861. int             temp;
  862. X
  863. X    /* insert the given vertex between the element where and its forward link */
  864. X
  865. X    /* remove an element from the free list */
  866. X    temp = poly[0][2];        /* free element */
  867. X    if (temp == endlist)
  868. X    {
  869. X    /* Need to make our list one longer. */
  870. X    endlist++;
  871. X    if (endlist >= POLYS)
  872. X        ERR (FATAL, name, "Ran out of memory on the polygon!");
  873. X    poly[endlist][3] = temp;
  874. X    poly[endlist][2] = ENDOFLIST;
  875. X    poly[temp][2] = endlist;
  876. X    }
  877. X    /* OK, Now you can remove it, it isn't at the end anymore. */
  878. X    poly[0][2] = poly[temp][2];
  879. X    poly[poly[temp][2]][3] = 0;
  880. X
  881. X    poly[temp][0] = x;        /* Put vertex in for element */
  882. X    poly[temp][1] = y;
  883. X    poly[temp][4] = z;
  884. X
  885. X    /* update links */
  886. X
  887. X    poly[temp][2] = poly[where][2];
  888. X    poly[where][2] = temp;
  889. X
  890. X    poly[temp][3] = poly[poly[temp][2]][3];
  891. X    poly[poly[temp][2]][3] = temp;
  892. X}
  893. X
  894. delete (where)
  895. X    int             where;
  896. X{
  897. int             temp;
  898. X
  899. X    /* Get rid of element number where; put it on the free list */
  900. X    /* This must work even if element where points to itself! */
  901. X    poly[where][0] = poly[where][1] = EMPTY;
  902. X    poly[where][4] = INTERIOR;
  903. X    temp = poly[where][3];
  904. X    poly[where][3] = 0;
  905. X    poly[temp][2] = poly[where][2];
  906. X    poly[where][2] = poly[0][2];
  907. X    poly[0][2] = where;
  908. X    poly[poly[where][2]][3] = where;
  909. X    poly[poly[temp][2]][3] = temp;
  910. X}
  911. X
  912. X/*
  913. X * See how many polygons we have, and where they start.
  914. X * Put this information in pols.
  915. X */
  916. scan ()
  917. X{
  918. int             polyon[POLYS];    /* Array to remember whom this point belongs
  919. X                 * to */
  920. int             joe;
  921. int             cycle;
  922. int             firstpoint;
  923. int             where;
  924. X
  925. X    for (joe = 1; joe < endlist; joe++)
  926. X    {
  927. X    if (poly[joe][0] == EMPTY)
  928. X    {
  929. X        polyon[joe] = EMPTY;
  930. X    }
  931. X    else
  932. X    {
  933. X        polyon[joe] = UNCLAIMED;
  934. X    }
  935. X    }
  936. X
  937. X    npols = 0;
  938. X    for (joe = 1; joe < endlist; joe++)
  939. X    {
  940. X    if (polyon[joe] == UNCLAIMED)
  941. X    {
  942. X        /* Found the start of a polygon */
  943. X        firstpoint = joe;
  944. X        polyon[firstpoint] = CLAIMED;
  945. X        cycle = 1;
  946. X        where = poly[firstpoint][2];
  947. X        while (firstpoint != where)
  948. X        {
  949. X        cycle++;
  950. X        polyon[where] = CLAIMED;
  951. X        where = poly[where][2];
  952. X        if (where == NOLINK)
  953. X            ERR (FATAL, name, "Oh, No! Polygon list damaged! (This shouldn't be able to happen.)");
  954. X        }
  955. X        if (cycle < 3)
  956. X        {            /* Not really a polygon, remove it */
  957. X        where = poly[firstpoint][2];
  958. X        while (firstpoint != where)
  959. X        {
  960. X            delete (where);
  961. X            where = poly[firstpoint][2];
  962. X        }
  963. X        delete (firstpoint);
  964. X        }
  965. X        else
  966. X        {
  967. X        /* We found another polygon */
  968. X        npols++;
  969. X        if (npols > MAXPOL)
  970. X            ERR (FATAL, name, "Too many polygons!");
  971. X        pols[npols] = firstpoint;
  972. X        polsc[npols] = cycle;
  973. X        }
  974. X    }
  975. X    }
  976. X}
  977. X /*
  978. X  * Now pols is a list of indexes to the beginnings of each of the  Polygons.
  979. X  * npols gives how many there are. 
  980. X  */
  981. X
  982. int
  983. edge (x, y)        /* Find out which edges this point is on */
  984. X    int             x, y;
  985. X{
  986. X    bottom = left = 0;
  987. X    if (x == xwmin)
  988. X    left = 2;
  989. X    if (y == ywmin)
  990. X    bottom = 1;
  991. X    if (x == xwmax)
  992. X    left = 8;
  993. X    if (y == ywmax)
  994. X    bottom = 4;
  995. X    return (bottom + left);
  996. X}
  997. END_OF_FILE
  998. if test 15037 -ne `wc -c <'Vplot_Kernel/filters/genlib/polyfix.c'`; then
  999.     echo shar: \"'Vplot_Kernel/filters/genlib/polyfix.c'\" unpacked with wrong size!
  1000. fi
  1001. # end of 'Vplot_Kernel/filters/genlib/polyfix.c'
  1002. fi
  1003. if test -f 'Vplot_Kernel/util/Ta2vplot.c' -a "${1}" != "-c" ; then 
  1004.   echo shar: Will not clobber existing file \"'Vplot_Kernel/util/Ta2vplot.c'\"
  1005. else
  1006. echo shar: Extracting \"'Vplot_Kernel/util/Ta2vplot.c'\" \(15559 characters\)
  1007. sed "s/^X//" >'Vplot_Kernel/util/Ta2vplot.c' <<'END_OF_FILE'
  1008. X/*
  1009. X * Ta2vplot - reads in a Taplot/Movie format file and outputs a vplot raster
  1010. X * file. 
  1011. X *
  1012. X * <moviefile.h  Ta2vplot xll=1. yll=1. xur=5. yur=5. nreserve=8 orient=1 invert=y
  1013. X * title=, label1=, label2=, titlefat=, titlesz= labelfat= labelsz= d1num=0.
  1014. X * o1num= d2num=0. o2num= grid=y frame=y polarity=1 coltab=y labelrot=0
  1015. X * axiscol=7 color=I backcol=red,green,blue hurry=y > vplotfile.H 
  1016. X *
  1017. X * esize:
  1018. X * 
  1019. X * If esize=1, then the input file is in "Taplot" format. Default is color=I.
  1020. X *
  1021. X * If esize=3, then the input file is assumed to contain RGB 3-byte triples.
  1022. X * The color number that corresponds to the "closest available color"
  1023. X * to that defined by the triple is used. Default is color=332.
  1024. X * Using Movie color schemes is slow. (BEWARE "color" set to the wrong
  1025. X * value by your history file!!!)
  1026. X *
  1027. X * Positioning the plot: 
  1028. X *
  1029. X * xll,yll are the coordinates of the lower left corner of the plot. xur,yur are
  1030. X * the coordinates of the upper right corner. orient=0,1,2,3 to start plot in
  1031. X * upper left, upper right, lower right, or lower left. invert=y 'flips' output
  1032. X * image to agree with movie display. 
  1033. X *
  1034. X * Annotation: 
  1035. X *
  1036. X * title,label1, and label2 are strings for axis labelling. titlefat and titlesz
  1037. X * are the fatness and size of the title. labelfat and labelsz are the fatness
  1038. X * and size of the axis labels. labelrot = 1 rotates label1 180 degrees o1num
  1039. X * and d1num are the starting value and increment for labelling the n1 axis.
  1040. X * o2num and d2num are the starting value and increment for labelling the n2
  1041. X * axis. grid=y places a grid line for each label. frame=y draws a frame around
  1042. X * the plot. axiscol determines the frame, label and title colors d1num = 0
  1043. X * turns off the labelling. d1num and d2num MUST be specified. negative fatness
  1044. X * turns off the title or labels. NOTE: labelling works properly only for
  1045. X * invert=y orient=1 at this time! 
  1046. X *
  1047. X * polarity=-1 flips the raster values black to white and white to black 
  1048. X *
  1049. X * If coltab=n, no color table definition is prepended to the vplot file. nreserve
  1050. X * is the number of colors for the plotting device that you want to be left
  1051. X * "free", ie not used in the raster color table. This prevents Ta2vplot from
  1052. X * overwriting vplot type colors with the grey scale used to display movie
  1053. X * files. 
  1054. X *
  1055. X * color= one of {I,i,F,R,W,G} just like in Movie, and also RGB, where
  1056. X * each of R,G, and B is the number of bits to allot to that primary.
  1057. X *
  1058. X * backcol=red,green,blue sets the background color. Each of {red,green,blue} are
  1059. X * between 0. and 1. 
  1060. X *
  1061. X * movish=n (if y, halves the color table like movie does) 
  1062. X *
  1063. X * The resulting vplot file can be displayed using any vplot pen filter.
  1064. X * Various device-dependent corrections are automatically made by vplot
  1065. X * to compensate for the peculiarities of each display device. Some of
  1066. X * these corrections can be controlled by the user. See "man pen" for
  1067. X * more details.
  1068. X *
  1069. X * Keywords: vplot plot movie raster hardcopy rgb color
  1070. X */
  1071. X/*
  1072. X * EDIT HISTORY:
  1073. X * Author Steve Cole, March 1987
  1074. X * Joe Dellinger, Dec 1987 fixed "color value too large" bug.
  1075. X * Steve Cole, Dec 1987, changed putch call for movish to avoid problem
  1076. X *     on suns.
  1077. X * Joe Dellinger, Jan 1988, fixed some bugs involving color mapping,
  1078. X *    and added capability for RGB triples.
  1079. X * Joe Dellinger Feb 25 1988, vp_style after vp_erase
  1080. X */
  1081. X#ifndef SOURCE
  1082. X#define SOURCE "/usr/src/sepsrc/Ta2vplot.c"
  1083. X#endif
  1084. X#include <sep.main>
  1085. X#include <stdio.h>
  1086. X#include <strings.h>
  1087. X#include <vplot.h>
  1088. X
  1089. X#define SQUARE(A) ((A)*(A))
  1090. X
  1091. int             cintensityp[9] =
  1092. X{
  1093. X 0, 128, 255, 0, 128, 255, 0, 128, 255
  1094. X};
  1095. int             cintensityn[9] =
  1096. X{
  1097. X 255, 128, 0, 255, 128, 0, 255, 128, 0
  1098. X};
  1099. int             cflag[9] =
  1100. X{
  1101. X 255, 255, 0, 0, 255, 0, 0, 255, 255
  1102. X};
  1103. int             cbi[9] =
  1104. X{
  1105. X 255, 0, 0, 0, 0, 0, 0, 0, 255
  1106. X};
  1107. int             csurf[9] =
  1108. X{
  1109. X 0, 0, 255, 0, 0, 255, 0, 200, 255
  1110. X};
  1111. int             cgsi[9] =
  1112. X{
  1113. X 0, 255, 255, 0, 255, 0, 0, 255, 0
  1114. X};
  1115. int            *cola;
  1116. X
  1117. MAIN ()
  1118. X{
  1119. int             n1, n2, n3, i3, i4, incr, ii, jj, kk, esize;
  1120. int             labelsz, titlesz, labelfat, titlefat;
  1121. int             labelrot, axiscol, sign;
  1122. float           d1, o1, d2, o2, d3, o3;
  1123. float           pos1, pos2;
  1124. float           xx, yy;
  1125. char            string[80];
  1126. float           d1num, d2num;
  1127. float           o1num, o2num;
  1128. int             grid, frame;
  1129. char            label1[80], label2[80], title[160];
  1130. int             offset, xpix, ypix, bit, blast, orient, invert;
  1131. float           xll, yll, xur, yur, ppi;
  1132. int             nreserve;
  1133. int             polarity, coltab;
  1134. unsigned char  *data;
  1135. char            color[10];
  1136. extern float    rd_color (), gr_color (), bl_color ();
  1137. float           backcol[3];
  1138. float           back = 0;
  1139. int             movish;
  1140. int             map[256];
  1141. int             smap[256];
  1142. float           red[256], green[256], blue[256];
  1143. float           red_lev, green_lev, blue_lev, error, error_win;
  1144. int             ired_lev, igreen_lev, iblue_lev;
  1145. int             win, redbit, greenbit, bluebit;
  1146. int             redbit2, greenbit2, bluebit2;
  1147. int             redoff, greenoff, blueoff;
  1148. X
  1149. X    if (!fetch ("n1", "d", &n1))
  1150. X    err ("n1 not given\n");
  1151. X    if (!fetch ("n2", "d", &n2))
  1152. X    err ("n2 not given\n");
  1153. X    if (!fetch ("n3", "d", &n3))
  1154. X    n3 = 1;
  1155. X    if (!fetch ("esize", "d", &esize))
  1156. X    err ("esize not given\n");
  1157. X
  1158. X    if (esize != 1 && esize != 3)
  1159. X    err ("esize must be 1 or 3\n");
  1160. X
  1161. X    coltab = 1;
  1162. X    fetch ("coltab", "1", &coltab);
  1163. X    if (!coltab && esize == 3)
  1164. X    err ("esize must be 1 if coltab=no\n");
  1165. X
  1166. X    if (esize == 1)
  1167. X    strcpy (color, "I");
  1168. X    else
  1169. X    strcpy (color, "332");
  1170. X    fetch ("color", "s", color);
  1171. X
  1172. X    if (!getch ("xll", "f", &xll))
  1173. X    xll = 1.;
  1174. X    if (!getch ("yll", "f", &yll))
  1175. X    yll = 1.;
  1176. X    if (!getch ("xur", "f", &xur))
  1177. X    xur = 5.;
  1178. X    if (!getch ("yur", "f", &yur))
  1179. X    yur = 5.;
  1180. X    if (!getch ("orient", "d", &orient))
  1181. X    orient = 1;
  1182. X    if (!getch ("nreserve", "d", &nreserve))
  1183. X    nreserve = 8;
  1184. X    if (!getch ("invert", "1", &invert))
  1185. X    invert = 1;
  1186. X    if (!getch ("movish", "1", &movish))
  1187. X    movish = 0;
  1188. X
  1189. X    putch_ ("movish", "d", &movish);
  1190. X
  1191. X    puthead ("\tn1=-1\n");
  1192. X
  1193. X    /* Polarity stuff */
  1194. X    polarity = 1;
  1195. X    fetch ("polarity", "d", &polarity);
  1196. X    putch ("polarity", "d", &polarity);
  1197. X
  1198. X    /* Axis and labelling parameters */
  1199. X    strcpy (label1, "");
  1200. X    strcpy (label2, "");
  1201. X    strcpy (title, "");
  1202. X    fetch ("label1", "s", label1);
  1203. X    fetch ("label2", "s", label2);
  1204. X    fetch ("title", "s", title);
  1205. X    o1 = 0.;
  1206. X    o2 = 0.;
  1207. X    d1 = 1.;
  1208. X    d2 = 1.;
  1209. X    fetch ("o1", "f", &o1);
  1210. X    fetch ("o2", "f", &o2);
  1211. X    fetch ("d1", "f", &d1);
  1212. X    fetch ("d2", "f", &d2);
  1213. X    d1num = 0.;
  1214. X    d2num = 0.;
  1215. X    o1num = o1;
  1216. X    o2num = o2;
  1217. X    fetch ("d1num", "f", &d1num);
  1218. X    fetch ("d2num", "f", &d2num);
  1219. X    fetch ("o1num", "f", &o1num);
  1220. X    fetch ("o2num", "f", &o2num);
  1221. X    labelsz = 5;
  1222. X    titlesz = 5;
  1223. X    labelfat = 1;
  1224. X    titlefat = 1;
  1225. X    fetch ("labelsz", "d", &labelsz);
  1226. X    fetch ("titlesz", "d", &titlesz);
  1227. X    fetch ("labelfat", "d", &labelfat);
  1228. X    fetch ("titlefat", "d", &titlefat);
  1229. X    labelrot = 0;
  1230. X    axiscol = 7;
  1231. X    fetch ("labelrot", "1", &labelrot);
  1232. X    fetch ("axiscol", "d", &axiscol);
  1233. X    sign = -1;
  1234. X    if (labelrot)
  1235. X    sign = 1;
  1236. X
  1237. X    frame = 1;
  1238. X    grid = 1;
  1239. X    fetch ("frame", "1", &frame);
  1240. X    fetch ("grid", "1", &grid);
  1241. X
  1242. X    if (fetch ("backcol", "f", backcol))
  1243. X    {
  1244. X    back = 1;
  1245. X    }
  1246. X    blast = 1;
  1247. X    fetch ("hurry", "1", &blast);
  1248. X
  1249. X    hclose ();
  1250. X
  1251. X    data = (unsigned char *) alloc (n1 * n2 * esize);
  1252. X
  1253. X    vp_erase ();
  1254. X    vp_style (STANDARD);
  1255. X    vp_color (axiscol);
  1256. X
  1257. X    if (coltab)
  1258. X    {
  1259. X
  1260. X    if (color[0] >= '0' && color[0] <= '9')
  1261. X    {
  1262. X        redbit = color[0] - '0';
  1263. X        greenbit = color[1] - '0';
  1264. X        bluebit = color[2] - '0';
  1265. X        if (redbit + greenbit + bluebit != 8)
  1266. X        err ("You must use exactly 8 bits!\n");
  1267. X
  1268. X        redoff = 0;
  1269. X        greenoff = redbit;
  1270. X        blueoff = redbit + greenbit;
  1271. X
  1272. X        for (i3 = 0; i3 < 256; i3++)
  1273. X        {
  1274. X        ii = ~(~0 << redbit);
  1275. X        if (ii > 0)
  1276. X            red[i3] = (float) ((i3 >> redoff) & ii) / (float) (ii);
  1277. X        else
  1278. X            red[i3] = 0.;
  1279. X
  1280. X        ii = ~(~0 << greenbit);
  1281. X        if (ii > 0)
  1282. X            green[i3] = (float) ((i3 >> greenoff) & ii) / (float) (ii);
  1283. X        else
  1284. X            green[i3] = 0.;
  1285. X
  1286. X        ii = ~(~0 << bluebit);
  1287. X        if (ii > 0)
  1288. X            blue[i3] = (float) ((i3 >> blueoff) & ii) / (float) (ii);
  1289. X        else
  1290. X            blue[i3] = 0.;
  1291. X        }
  1292. X
  1293. X        for (i3 = 256; i3 < 512; i3++)
  1294. X        {
  1295. X        jj = i3 - 256;
  1296. X
  1297. X        if (movish)
  1298. X            jj = 2 * (int) (jj / 2);
  1299. X        vp_coltab (i3, red[jj], green[jj], blue[jj]);
  1300. X        }
  1301. X
  1302. X        for (jj = 0; jj < 256; jj++)
  1303. X        {
  1304. X        ii = 0;
  1305. X        greenbit2 = greenbit;
  1306. X        bluebit2 = bluebit;
  1307. X        redbit2 = redbit;
  1308. X        kk = 0;
  1309. X        while (kk < 8)
  1310. X        {
  1311. X            greenbit2--;
  1312. X            if (greenbit2 >= 0)
  1313. X            {
  1314. X            if (jj & (1 << (greenbit2 + greenoff)))
  1315. X                ii |= 1 << kk;
  1316. X            kk++;
  1317. X            }
  1318. X
  1319. X            redbit2--;
  1320. X            if (redbit2 >= 0)
  1321. X            {
  1322. X            if (jj & (1 << (redbit2 + redoff)))
  1323. X                ii |= 1 << kk;
  1324. X            kk++;
  1325. X            }
  1326. X
  1327. X            bluebit2--;
  1328. X            if (bluebit2 >= 0)
  1329. X            {
  1330. X            if (jj & (1 << (bluebit2 + blueoff)))
  1331. X                ii |= 1 << kk;
  1332. X            kk++;
  1333. X            }
  1334. X        }
  1335. X        map[ii] = jj;
  1336. X        }
  1337. X
  1338. X        for (i3 = nreserve; i3 < 256; i3++)
  1339. X        {
  1340. X        jj = i3 - nreserve;
  1341. X
  1342. X        vp_coltab (i3, red[map[jj]],
  1343. X               green[map[jj]],
  1344. X               blue[map[jj]]);
  1345. X        }
  1346. X    }
  1347. X    else
  1348. X    {
  1349. X        switch (*color)
  1350. X        {
  1351. X        case 'i':
  1352. X        cola = cintensityn;
  1353. X        break;
  1354. X        case 'F':
  1355. X        cola = cflag;
  1356. X        break;
  1357. X        case 'R':
  1358. X        cola = cbi;
  1359. X        break;
  1360. X        case 'W':
  1361. X        cola = csurf;
  1362. X        break;
  1363. X        case 'G':
  1364. X        cola = cgsi;
  1365. X        break;
  1366. X        case 'I':
  1367. X        default:
  1368. X        cola = cintensityp;
  1369. X        break;
  1370. X        }
  1371. X
  1372. X        /*
  1373. X         * set up a perfect grey scale in colors 256-511. the offset in
  1374. X         * vp_raster maps the pixels into that range. no device actually
  1375. X         * has such colors, so vplot looks at those colors the device
  1376. X         * does have (0 through some n) and picks out the one closest to
  1377. X         * the desired grey. thus by setting up black, white, 50% grey,
  1378. X         * 75% grey, 25% grey, ... in 0-255, we'll get the best grey
  1379. X         * scale for the device. 
  1380. X         *
  1381. X         * note: we leave colors 0 through nreserve-1 alone, since they are
  1382. X         * already defined for the device. 
  1383. X         *
  1384. X         */
  1385. X        for (i3 = 0; i3 < 256; i3++)
  1386. X        {
  1387. X        red[i3] = rd_color ((float) i3);
  1388. X        green[i3] = gr_color ((float) i3);
  1389. X        blue[i3] = bl_color ((float) i3);
  1390. X        }
  1391. X
  1392. X        for (i3 = 256; i3 < 512; i3++)
  1393. X        {
  1394. X        jj = i3 - 256;
  1395. X
  1396. X        if (movish)
  1397. X            jj = 2 * (int) (jj / 2);
  1398. X        vp_coltab (i3, red[jj], green[jj], blue[jj]);
  1399. X        }
  1400. X
  1401. X        /*
  1402. X         * set the lower grey scale, which will give us the best grey
  1403. X         * scale possible for the device. 
  1404. X         *
  1405. X         * we assume that the device already has colors white and black set. 
  1406. X         */
  1407. X
  1408. X        i3 = 0;
  1409. X        smap[i3] = 0;
  1410. X        i3++;
  1411. X        if (nreserve == 0)
  1412. X        {
  1413. X        smap[i3] = 255;
  1414. X        i3++;
  1415. X        }
  1416. X        for (incr = 2; incr < 512; incr *= 2)
  1417. X        {
  1418. X        for (i4 = 1; i4 < incr; i4 += 2)
  1419. X        {
  1420. X            jj = i4 * 256 / incr;
  1421. X            smap[i3] = jj;
  1422. X            i3++;
  1423. X            if (i3 == 256)
  1424. X            break;
  1425. X        }
  1426. X        }
  1427. X
  1428. X        for (i3 = nreserve; i3 < 256; i3++)
  1429. X        {
  1430. X        jj = i3 - nreserve;
  1431. X
  1432. X        vp_coltab (i3, red[smap[jj]],
  1433. X               green[smap[jj]],
  1434. X               blue[smap[jj]]);
  1435. X        }
  1436. X
  1437. X    }
  1438. X    if (back)
  1439. X        vp_coltab (0, backcol[0], backcol[1], backcol[2]);
  1440. X    }
  1441. X    /* Set the coordinate transformation */
  1442. X    vp_orig (xll, yur);
  1443. X    vp_uorig (o2, o1);
  1444. X    vp_scale ((xur - xll) / (d2 * n2), (yll - yur) / (d1 * n1));
  1445. X
  1446. X
  1447. X    /*
  1448. X     * Do the plots 
  1449. X     */
  1450. X
  1451. X    for (i3 = 0; i3 < n3; i3++)
  1452. X    {
  1453. X    if (i3 != 0)
  1454. X    {
  1455. X        vp_erase ();
  1456. X        vp_style (STANDARD);
  1457. X        vp_color (axiscol);
  1458. X    }
  1459. X    reed (infd, data, n1 * n2 * esize);
  1460. X    if (polarity < 0)
  1461. X        for (ii = 0; ii < n1 * n2 * esize; ii++)
  1462. X        {
  1463. X        data[ii] = (unsigned char) 255 - data[ii];
  1464. X        }
  1465. X/*
  1466. X * If esize=3, then map the RGB triples onto the closest available
  1467. X * color.
  1468. X */
  1469. X    if (esize == 3)
  1470. X    {
  1471. X        if (color[0] >= '0' && color[0] <= '9')
  1472. X        {
  1473. X        for (ii = 0; ii < n1 * n2; ii++)
  1474. X        {
  1475. X            ired_lev = data[esize * ii];
  1476. X            igreen_lev = data[esize * ii + 1];
  1477. X            iblue_lev = data[esize * ii + 2];
  1478. X
  1479. X            win = 0;
  1480. X            win |= ((ired_lev >> (8 - redbit)) & ~(~0 << redbit)) << redoff;
  1481. X            win |= ((igreen_lev >> (8 - greenbit)) & ~(~0 << greenbit)) << greenoff;
  1482. X            win |= ((iblue_lev >> (8 - bluebit)) & ~(~0 << bluebit)) << blueoff;
  1483. X            data[ii] = win;
  1484. X        }
  1485. X        }
  1486. X        else
  1487. X        {
  1488. X        for (ii = 0; ii < n1 * n2; ii++)
  1489. X        {
  1490. X            red_lev = data[esize * ii] / 255.;
  1491. X            green_lev = data[esize * ii + 1] / 255.;
  1492. X            blue_lev = data[esize * ii + 2] / 255.;
  1493. X            error_win = 8.;
  1494. X            for (jj = 0; jj < 256; jj++)
  1495. X            {
  1496. X            error = 2. * SQUARE (red_lev - red[jj]) + 4. * SQUARE (green_lev - green[jj]) + SQUARE (blue_lev - blue[jj]);
  1497. X            if (error < error_win)
  1498. X            {
  1499. X                error_win = error;
  1500. X                win = jj;
  1501. X                if (error == 0.)
  1502. X                break;
  1503. X            }
  1504. X            }
  1505. X            data[ii] = win;
  1506. X        }
  1507. X        }
  1508. X    }
  1509. X
  1510. X    /*
  1511. X     * Only offset the colors if we have defined a color table.
  1512. X     * Otherwise, leave them alone. 
  1513. X     */
  1514. X    if (coltab)
  1515. X        offset = 256;
  1516. X    else
  1517. X        offset = 0;
  1518. X
  1519. X    xpix = n1;
  1520. X    ypix = n2;
  1521. X    bit = 0;
  1522. X    ppi = 0;
  1523. X    vp_raster (data, blast, bit, offset, xpix, ypix, xll, yll, ppi, &xur, &yur, orient, invert);
  1524. X
  1525. X    vp_fat (1);
  1526. X    if (frame)
  1527. X    {
  1528. X        vp_move (xll, yll);
  1529. X        vp_draw (xll, yur);
  1530. X        vp_draw (xur, yur);
  1531. X        vp_draw (xur, yll);
  1532. X        vp_draw (xll, yll);
  1533. X    }
  1534. X    if (grid)
  1535. X    {
  1536. X        if (d2num > 0)
  1537. X        {
  1538. X        for (pos2 = o2num; pos2 <= o2 + n2 * d2; pos2 += d2num)
  1539. X        {
  1540. X            vp_umove (pos2, o1);
  1541. X            vp_udraw (pos2, o1 + n1 * d1);
  1542. X        }
  1543. X        }
  1544. X        if (d1num > 0)
  1545. X        {
  1546. X        for (pos1 = o1num; pos1 <= o1 + n1 * d1; pos1 += d1num)
  1547. X        {
  1548. X            vp_umove (o2, pos1);
  1549. X            vp_udraw (o2 + n2 * d2, pos1);
  1550. X        }
  1551. X        }
  1552. X    }
  1553. X    if (d2num > 0)
  1554. X    {
  1555. X        vp_fat (labelfat);
  1556. X        vp_tjust (TH_CENTER, TV_BASE);
  1557. X        for (pos2 = o2num; pos2 <= o2 + n2 * d2; pos2 += d2num)
  1558. X        {
  1559. X        vp_umove (pos2, o1);
  1560. X        vp_where (&xx, &yy);
  1561. X        yy += .07;
  1562. X        vp_draw (xx, yy);
  1563. X        yy += .03;
  1564. X        sprintf (string, "%g", pos2);
  1565. X        vp_text (xx, yy, labelsz, 0, string);
  1566. X        }
  1567. X    }
  1568. X    if (d1num > 0)
  1569. X    {
  1570. X        vp_fat (labelfat);
  1571. X        vp_tjust (TH_CENTER, TV_TOP);
  1572. X        for (pos1 = o1num; pos1 <= o1 + n1 * d1; pos1 += d1num)
  1573. X        {
  1574. X        vp_umove (o2, pos1);
  1575. X        vp_where (&xx, &yy);
  1576. X        xx -= .07;
  1577. X        vp_draw (xx, yy);
  1578. X        xx -= .03;
  1579. X        sprintf (string, "%g", pos1);
  1580. X        vp_text (xx, yy, labelsz, -90, string);
  1581. X        }
  1582. X    }
  1583. X    vp_move ((xll + xur) / 2., yur);
  1584. X    vp_where (&xx, &yy);
  1585. X    yy += .07;
  1586. X    yy += .03;
  1587. X    yy += labelsz / TXPERIN;
  1588. X    yy += .15;
  1589. X    vp_fat (labelfat);
  1590. X    vp_tjust (TH_CENTER, TV_BASE);
  1591. X    vp_text (xx, yy, labelsz, 0, label2);
  1592. X
  1593. X    yy += labelsz / TXPERIN;
  1594. X    yy += .15;
  1595. X    vp_fat (titlefat);
  1596. X    vp_tjust (TH_CENTER, TV_BOTTOM);
  1597. X    vp_text (xx, yy, titlesz, 0, title);
  1598. X
  1599. X    vp_move (xll, (yll + yur) / 2.);
  1600. X    vp_where (&xx, &yy);
  1601. X    xx -= .07;
  1602. X    xx -= .03;
  1603. X    xx -= labelsz / TXPERIN;
  1604. X    xx -= .15;
  1605. X    vp_fat (labelfat);
  1606. X    if (labelrot)
  1607. X        vp_tjust (TH_CENTER, TV_BOTTOM);
  1608. X    else
  1609. X        vp_tjust (TH_CENTER, TV_TOP);
  1610. X    vp_text (xx, yy, labelsz, sign * 90, label1);
  1611. X    }
  1612. X}
  1613. X
  1614. float
  1615. rd_color (x)
  1616. X    float           x;
  1617. X{
  1618. X    if (x < 128)
  1619. X    return (((128. - x) * (float) cola[0] / 128.) + (x * (float) cola[1] / 128.)) / 255.;
  1620. X    else
  1621. X    return (((255. - x) * (float) cola[1] / 127.) + ((x - 128.) * (float) cola[2] / 127.)) / 255.;
  1622. X}
  1623. X
  1624. float
  1625. gr_color (x)
  1626. X    float           x;
  1627. X{
  1628. X    if (x < 128)
  1629. X    return (((128. - x) * (float) cola[3] / 128.) + (x * (float) cola[4] / 128.)) / 255.;
  1630. X    else
  1631. X    return (((255. - x) * (float) cola[4] / 127.) + ((x - 128.) * (float) cola[5] / 127.)) / 255.;
  1632. X}
  1633. X
  1634. float
  1635. bl_color (x)
  1636. X    float           x;
  1637. X{
  1638. X    if (x < 128)
  1639. X    return (((128. - x) * (float) cola[6] / 128.) + (x * (float) cola[7] / 128.)) / 255.;
  1640. X    else
  1641. X    return (((255. - x) * (float) cola[7] / 127.) + ((x - 128.) * (float) cola[8] / 127.)) / 255.;
  1642. X}
  1643. END_OF_FILE
  1644. if test 15559 -ne `wc -c <'Vplot_Kernel/util/Ta2vplot.c'`; then
  1645.     echo shar: \"'Vplot_Kernel/util/Ta2vplot.c'\" unpacked with wrong size!
  1646. fi
  1647. # end of 'Vplot_Kernel/util/Ta2vplot.c'
  1648. fi
  1649. echo shar: End of archive 17 \(of 24\).
  1650. cp /dev/null ark17isdone
  1651. MISSING=""
  1652. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ; do
  1653.     if test ! -f ark${I}isdone ; then
  1654.     MISSING="${MISSING} ${I}"
  1655.     fi
  1656. done
  1657. if test "${MISSING}" = "" ; then
  1658.     echo You have unpacked all 24 archives.
  1659.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1660. else
  1661.     echo You still need to unpack the following archives:
  1662.     echo "        " ${MISSING}
  1663. fi
  1664. ##  End of shell archive.
  1665. exit 0
  1666.