home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / x3d / part06 < prev    next >
Encoding:
Internet Message Format  |  1992-02-05  |  26.5 KB

  1. Path: uunet!think.com!mips!msi!dcmartin
  2. From: spy@castlab.engr.wisc.edu (Mark Spychalla)
  3. Newsgroups: comp.sources.x
  4. Subject: v16i051: 3D Wireframe viewer, Part06/06
  5. Message-ID: <1992Feb6.144046.29531@msi.com>
  6. Date: 6 Feb 92 14:40:46 GMT
  7. References: <csx-16i046-x3d@uunet.UU.NET>
  8. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  9. Organization: Molecular Simulations, Inc.
  10. Lines: 881
  11. Approved: dcmartin@msi.com
  12. Originator: dcmartin@fascet
  13.  
  14. Submitted-by: spy@castlab.engr.wisc.edu (Mark Spychalla)
  15. Posting-number: Volume 16, Issue 51
  16. Archive-name: x3d/part06
  17.  
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  22. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  23. # If this archive is complete, you will see the following message at the end:
  24. #        "End of archive 6 (of 6)."
  25. # Contents:  con/con.c constants.h gi.h
  26. # Wrapped by dcmartin@fascet on Thu Feb  6 06:38:06 1992
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'con/con.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'con/con.c'\"
  30. else
  31. echo shar: Extracting \"'con/con.c'\" \(17970 characters\)
  32. sed "s/^X//" >'con/con.c' <<'END_OF_FILE'
  33. X/*
  34. X  Copyright 1992 Mark Spychalla
  35. X
  36. X  Permission to use, copy, modify, distribute, and sell this software and
  37. X  its documentation for any purpose is hereby granted without fee,
  38. X  provided that the above copyright notice appear in all copies and that
  39. X  both that copyright notice and this permission notice appear in
  40. X  supporting documentation, and that the name of Mark Spychalla not be used
  41. X  in advertising or publicity pertaining to distribution of the software
  42. X  without specific, written prior permission.  Mark Spychalla makes no
  43. X  representations about the suitability of this software for any purpose.
  44. X  It is provided "as is" without express or implied warranty.
  45. X
  46. X  Mark Spychalla disclaims all warranties with regard to this software,
  47. X  including all implied warranties of merchantability and fitness, in no
  48. X  event shall Mark Spychalla be liable for any special, indirect or
  49. X  consequential damages or any damages whatsoever resulting from loss of use,
  50. X  data or profits, whether in an action of contract, negligence or other
  51. X  tortious action, arising out of or in connection with the use or performance
  52. X  of this software.
  53. X*/
  54. X
  55. X#include <stdio.h>
  56. X#include <math.h>
  57. X#include <string.h>
  58. X
  59. X#define MAXSTACK    100
  60. X#define STOP        10 
  61. X#define QSORT_ERROR -1 
  62. X#define PRECISION 100000.0
  63. X#define P 1
  64. X#define Q 0
  65. X#define MAX 80000
  66. X
  67. X#define copyMem(src, dest, size)    memcpy(dest, src, size);
  68. X
  69. X#define swapPtrs(ptr1, ptr2)                                         \
  70. X       ptr1 = (char *)((long)ptr1 ^ (long)ptr2);                     \
  71. X       ptr2 = (char *)((long)ptr2 ^ (long)ptr1);                     \
  72. X       ptr1 = (char *)((long)ptr1 ^ (long)ptr2);
  73. X
  74. X#define median5(v1,v2,v3,v4,v5)                                      \
  75. X   if(compare(v1,v2) > 0){                                           \
  76. X      swapPtrs(v1,v2)                                                \
  77. X      }                                                              \
  78. X   if(compare(v3,v4) > 0){                                           \
  79. X      swapPtrs(v3,v4)                                                \
  80. X      }                                                              \
  81. X   if(compare(v1,v3) > 0){                                           \
  82. X      swapPtrs(v1,v3)                                                \
  83. X      swapPtrs(v2,v4)                                                \
  84. X      }                                                              \
  85. X   if(compare(v2,v5) > 0){                                           \
  86. X      swapPtrs(v2,v5)                                                \
  87. X      }                                                              \
  88. X   if(compare(v2,v3) > 0){                                           \
  89. X      swapPtrs(v2,v3)                                                \
  90. X      swapPtrs(v4,v5)                                                \
  91. X      }                                                              \
  92. X   if(compare(v3,v5) > 0){                                           \
  93. X      swapPtrs(v3,v5)                                                \
  94. X      }
  95. X
  96. Xtypedef struct _Segment{
  97. X   struct _Point *p, *q;
  98. X   int x, y, z;
  99. X   int valid;
  100. X} Segment;
  101. X
  102. Xtypedef struct _SegList{
  103. X   Segment *seg;
  104. X   struct _SegList *next;
  105. X   int endPoint;
  106. X} SegList;
  107. X
  108. Xtypedef struct _Point{
  109. X   int x, y, z;
  110. X   Segment *seg;
  111. X   SegList *segList;
  112. X   int endPoint, valid, index;
  113. X} Point;
  114. X
  115. Xtypedef struct _StackElement{
  116. X   int start, end;
  117. X} StackElement;
  118. X
  119. X/*
  120. X   Compilers often mess up with pointers to functions, play with
  121. X   the type definition until it works
  122. X */
  123. X
  124. X/* typedef int (*cmp)(char *, char *); */
  125. X
  126. Xtypedef int cmp();
  127. X
  128. XSegList segLists[MAX];
  129. XSegment segments[MAX];
  130. XPoint points[MAX];
  131. X
  132. Xint qsort2(base, numElements, elementSize, compare)
  133. Xchar *base;
  134. Xint numElements, elementSize;
  135. Xcmp compare;
  136. X/*****************************************************************************
  137. X   Do a version of quicksort.  Quicksort has several problems;
  138. X
  139. X      1) Can be N*N not N(lg(N)) in worst cast of sorted input.
  140. X      2) It is not stable (equal elements may be in a different order than
  141. X         they were initially)
  142. X      3) Not in place (requires an amout of extra space that is not constant
  143. X         for any list of length N).
  144. X      4) Performs poorly on short lists (lots of stack overhead)
  145. X      5) It can do a great deal of element swapping.
  146. X
  147. X   We try to avoid poor splits by using a median of 5 split.
  148. X   We don't care whether it's stable or in place.
  149. X   We use insertion sort to do short lists.
  150. X   We swap lots of elements anyway.
  151. X
  152. X   This version of quicksort tries to avoid the BAD cases, and should
  153. X   perform a bit better than your C library's qsort().
  154. X
  155. X   If you are sorting huge elements you could improve performance by using
  156. X   some extra space and sorting an array of pointers to the elements instead.
  157. X*****************************************************************************/
  158. X{
  159. Xregister int stackIndex, stackNotSet, length, start, end, high;
  160. Xchar *v0, *v1, *v2, *v3, *v4, *v5, *v6;
  161. X
  162. X/* Sort stack max OK for lists of more than 1.2677 x 10^30 elements */
  163. XStackElement stack[MAXSTACK];
  164. X
  165. X/* Initialize our stack */
  166. X
  167. X   if((v0 = (char *)malloc(elementSize * sizeof(char))) == NULL)
  168. X      return QSORT_ERROR;
  169. X
  170. X   stackIndex = 1;
  171. X   stackNotSet = 0;
  172. X   start = 0; 
  173. X   end = numElements - 1;
  174. X
  175. X/* Do Qsort */
  176. X
  177. X   while(stackIndex){
  178. X
  179. X       if(stackNotSet){
  180. X          start = stack[stackIndex].start; 
  181. X          end = stack[stackIndex].end;
  182. X       }
  183. X       
  184. X       stackIndex--;
  185. X       stackNotSet = 1;
  186. X       length = end - start;
  187. X
  188. X/* Big enough to qsort ? */
  189. X
  190. X      if(length > STOP){
  191. X
  192. X         v1 = (base + (elementSize * (start)));
  193. X         v2 = (base + (elementSize * (start + (length / 4))));
  194. X         v3 = (base + (elementSize * (start + (length / 2))));
  195. X         v4 = (base + (elementSize * (start + ((length * 3) / 4))));
  196. X         v5 = (base + (elementSize * (end)));
  197. X         v6 = v1;
  198. X
  199. X/* Find median */
  200. X     
  201. X         median5(v1,v2,v3,v4,v5)
  202. X
  203. X         copyMem(v3, v0, elementSize)
  204. X         copyMem(v6, v3, elementSize)
  205. X         copyMem(v0, v6, elementSize)
  206. X
  207. X         v1 = base + (elementSize * (start + 1));
  208. X         v2 = base + (elementSize * end);
  209. X
  210. X/* Split */
  211. X
  212. X         while(compare(v2, v6) > 0) v2 -= elementSize;
  213. X         while(compare(v1, v6) < 0)  v1 += elementSize;
  214. X
  215. X         v5 = v0;
  216. X
  217. X         while(v1 < v2){
  218. X
  219. X            copyMem(v2, v5, elementSize)
  220. X            copyMem(v1, v2, elementSize)
  221. X            v5 = v1;
  222. X
  223. X            do{
  224. X               v2 -= elementSize;
  225. X            }while(compare(v2, v6) > 0);
  226. X
  227. X            do{
  228. X               v1 += elementSize;
  229. X            }while(compare(v1, v6) < 0);
  230. X
  231. X         }
  232. X         
  233. X         v2 = v1 - elementSize;
  234. X
  235. X         copyMem(v2, v5, elementSize)
  236. X         copyMem(v6, v2, elementSize)
  237. X         copyMem(v0, v6, elementSize)
  238. X
  239. X         high = (int)((v2 - base) / elementSize);
  240. X
  241. X/* Put sublists on the stack, smallest on top */
  242. X     
  243. X         if((high - start) > (end - high)){
  244. X            stack[++stackIndex].start = start; 
  245. X            stack[stackIndex].end = high - 1; 
  246. X            ++stackIndex; 
  247. X            start = high + 1; 
  248. X            stackNotSet = 0;
  249. X         }else{ 
  250. X            stack[++stackIndex].start = high + 1; 
  251. X            stack[stackIndex].end = end;
  252. X            ++stackIndex; 
  253. X            end = high - 1; 
  254. X            stackNotSet = 0;
  255. X            }
  256. X      }else{
  257. X
  258. X/* insertion sort the small lists */
  259. X
  260. X         v2 = (base + (elementSize * start));
  261. X         v3 = (base + (elementSize * end));
  262. X         v4 = v2 + elementSize;
  263. X
  264. X         while(v4 <= v3){
  265. X
  266. X            copyMem(v4, v0, elementSize)
  267. X            v1 = v4 - elementSize;
  268. X
  269. X            while((v1 >= v2) && ((compare(v1, v0)) > 0)){
  270. X               copyMem(v1, v1 + elementSize, elementSize)
  271. X               v1 -= elementSize; 
  272. X               }
  273. X            
  274. X            copyMem(v0, v1 + elementSize, elementSize)
  275. X            v4 += elementSize;
  276. X            }
  277. X
  278. X         }
  279. X      }
  280. X   free(v0);
  281. X}      
  282. X
  283. X
  284. X
  285. Xint comparePoints(p,q)
  286. XPoint *p, *q;
  287. X{
  288. Xint value;
  289. X
  290. X   value = 0;
  291. X
  292. X   if(p->x > q->x)
  293. X      value = 1;
  294. X   else    
  295. X      if(p->x < q->x)
  296. X         value = -1;
  297. X      else    
  298. X         if(p->y < q->y)
  299. X            value = -1;
  300. X         else    
  301. X            if(p->z < q->z)
  302. X               value = -1;
  303. X            else    
  304. X               if(p->z > q->z)
  305. X                  value = 1;
  306. X               else    
  307. X                  if(p->y > q->y)
  308. X                     value = 1;
  309. X   return value;
  310. X}
  311. X
  312. X
  313. X
  314. Xvoid reduceLines(list)
  315. X/*****************************************************************************
  316. X   The idea here is that we have a list of segments that share a common
  317. X   endpoint and we would like to get rid of any redundant information in
  318. X   the list by eliminating duplicate lines and coalescing colinear segments.
  319. X
  320. X   This routine probably does not work correctly.
  321. X*****************************************************************************/
  322. XSegList *list;
  323. X{
  324. XSegList *lead, *follow;
  325. X
  326. X   follow = list;
  327. X
  328. X/* Now we have a list of segments that share a common endpoint, check to 
  329. X   if any of these are colinear, if so, simplify the list */
  330. X
  331. X   while(follow){
  332. X      lead = follow->next;
  333. X
  334. X      while(lead){
  335. X         if((lead->seg->x == follow->seg->x) &&
  336. X         (lead->seg->y == follow->seg->y) &&
  337. X         (lead->seg->z == follow->seg->z)){
  338. X
  339. X            if(lead->endPoint == follow->endPoint){
  340. X
  341. X/* segments overlap, dispose of the shorter one */
  342. X
  343. X               if(lead->endPoint){
  344. X                  if(lead->seg->q > follow->seg->q){
  345. X                     follow->seg->valid = 0;
  346. X                  }else{
  347. X                     lead->seg->valid = 0;
  348. X                     }
  349. X               }else{
  350. X                  if(lead->seg->p < follow->seg->p){
  351. X                     follow->seg->valid = 0;
  352. X                  }else{
  353. X                     lead->seg->valid = 0;
  354. X                     }
  355. X                  }
  356. X
  357. X            }else{
  358. X
  359. X/* otherwise segments point opposite ways from this endpoint, replace the
  360. X   segments with their concatenation. */
  361. X
  362. X               if(lead->endPoint){
  363. X                     lead->seg->p = follow->seg->p;
  364. X                     follow->seg->q = lead->seg->q;
  365. X               }else{
  366. X                     follow->seg->p = lead->seg->p;
  367. X                     lead->seg->q = follow->seg->q;
  368. X                  }
  369. X
  370. X               lead = NULL;
  371. X
  372. X               }
  373. X            }
  374. X         if(lead)
  375. X            lead = lead->next; 
  376. X         }
  377. X      follow = follow->next;
  378. X      }
  379. X}
  380. X
  381. X
  382. X
  383. Xvoid readSegments(filename, scale, pointReturn, segmentReturn)
  384. Xchar *filename;
  385. Xfloat scale;
  386. Xint *pointReturn, *segmentReturn;
  387. X/*****************************************************************************
  388. X    Read a list of segments in from a file.
  389. X*****************************************************************************/
  390. X{
  391. XFILE *fd;
  392. Xint count;
  393. Xint index, value;
  394. Xint point, segment;
  395. XPoint *p, *q;
  396. Xfloat x1, y1, z1, x2, y2, z2;
  397. Xdouble length, dz, dx, dy;
  398. X
  399. X   for(index = 0; index < MAX; index++){
  400. X      points[index].valid = 0;
  401. X      segments[index].valid = 0;
  402. X      }
  403. X
  404. X   fd = stdin;
  405. X
  406. X   if((strcmp(filename, "-")) && ((fd = fopen(filename, "r")) == NULL)){
  407. X      fprintf(stderr, "Unable to open file: %s\n", filename);
  408. X      exit(1);
  409. X      }
  410. X
  411. X   point = 0;
  412. X   segment = 0;
  413. X
  414. X   count = fscanf(fd, "%f %f %f %f %f %f\n", &x1, &y1, &z1, &x2, &y2, &z2);
  415. X   
  416. X   while(count == 6){
  417. X
  418. X/* Fill in the points data structure */
  419. X
  420. X      points[point].x = (int)(x1 * scale);
  421. X      points[point].y = (int)(y1 * scale);
  422. X      points[point].z = (int)(z1 * scale);
  423. X
  424. X      p = &(points[point]);
  425. X      point++;
  426. X
  427. X      points[point].x = (int)(x2 * scale);
  428. X      points[point].y = (int)(y2 * scale);
  429. X      points[point].z = (int)(z2 * scale);
  430. X  
  431. X      q = &(points[point]);
  432. X
  433. X      value = comparePoints(p,q);
  434. X
  435. X/* We want P to be the lesser of the two points, duplicate p & q not allowed */
  436. X
  437. X      if(value > 0){
  438. X         swapPtrs((char *)p, (char *)q);
  439. X         dx = (double)(x1 - x2);
  440. X         dy = (double)(y1 - y2);
  441. X         dz = (double)(z1 - z2);
  442. X      }else{
  443. X         dx = (double)(x2 - x1);
  444. X         dy = (double)(y2 - y1);
  445. X         dz = (double)(z2 - z1);
  446. X         }
  447. X      
  448. X      if(value == 0){
  449. X         point -= 2;
  450. X         segment--;
  451. X      }else{
  452. X
  453. X         p->seg = &(segments[segment]);
  454. X         p->endPoint = P; 
  455. X         p->segList = NULL;
  456. X         p->valid = 1;
  457. X
  458. X         q->seg = &(segments[segment]);
  459. X         q->endPoint = Q; 
  460. X         q->segList = NULL;
  461. X         q->valid = 1;
  462. X
  463. X         length = sqrt(dx * dx + dy * dy + dz * dz);
  464. X
  465. X         segments[segment].x = (int)((dx / length) * PRECISION);
  466. X         segments[segment].y = (int)((dy / length) * PRECISION);
  467. X         segments[segment].z = (int)((dz / length) * PRECISION);
  468. X
  469. X         segments[segment].p = 0; 
  470. X         segments[segment].q = 0; 
  471. X         segments[segment].valid = 1;
  472. X
  473. X         }
  474. X
  475. X      point++;
  476. X      segment++;
  477. X
  478. X      count = fscanf(fd, "%f %f %f %f %f %f\n", &x1, &y1, &z1, &x2, &y2, &z2);
  479. X      }
  480. X
  481. X   fclose(fd);
  482. X   *pointReturn = point;
  483. X   *segmentReturn = segment;
  484. X}
  485. X
  486. X
  487. X
  488. Xvoid eliminateDuplicates(point, segment, numPoints, numSegments)
  489. Xint point, segment;
  490. Xint *numPoints, *numSegments;
  491. X/*****************************************************************************
  492. X    Eliminate duplicate points and segments.
  493. X*****************************************************************************/
  494. X{
  495. Xint count, segListIndex;
  496. Xint index, index2;
  497. X
  498. X/* sort the list of points */
  499. X
  500. X   qsort2(points, point, sizeof(Point), comparePoints);
  501. X
  502. X/* Set up the segments */
  503. X
  504. X   for(index = 0; index < point; index++){
  505. X      if(points[index].endPoint)
  506. X         points[index].seg->p = &(points[index]);
  507. X      else
  508. X         points[index].seg->q = &(points[index]);
  509. X      }
  510. X   
  511. X   index = 0;
  512. X   segListIndex = 0;
  513. X
  514. X/* remove duplicate points */
  515. X
  516. X   while(index < point){
  517. X
  518. X      index2 = index + 1;
  519. X      
  520. X      while((index2 < point) && ((comparePoints(&(points[index]),
  521. X         &(points[index2]))) == 0)){
  522. X
  523. X/* Switch the segment's endpoint */
  524. X
  525. X            if(points[index2].endPoint)
  526. X               points[index2].seg->p = &(points[index]);
  527. X            else
  528. X               points[index2].seg->q = &(points[index]);
  529. X
  530. X/* Add points[index2]'s segment to the list of segments that share this
  531. X   endpoint */
  532. X
  533. X            segLists[segListIndex].next = points[index].segList;
  534. X            segLists[segListIndex].seg  = points[index2].seg;
  535. X            segLists[segListIndex].endPoint = points[index2].endPoint;
  536. X            points[index].segList = &(segLists[segListIndex]);
  537. X            segListIndex++;
  538. X
  539. X/* points[index2] is no longer valid */
  540. X
  541. X            points[index2].valid = 0;
  542. X            index2++;
  543. X         }
  544. X
  545. X      segLists[segListIndex].next = points[index].segList;
  546. X      segLists[segListIndex].seg  = points[index].seg;
  547. X      segLists[segListIndex].endPoint = points[index].endPoint;
  548. X      points[index].segList = &(segLists[segListIndex]);
  549. X      segListIndex++;
  550. X
  551. X      index = index2;
  552. X      }
  553. X
  554. X/* Get rid of redundant segments */
  555. X
  556. X   for(index = 0; index < point; index++){
  557. X      reduceLines(points[index].segList);
  558. X      }
  559. X
  560. X/* More points may have disappeared, get rid of them */
  561. X
  562. X   for(index = 0; index < point; index++)
  563. X      points[index].valid = 0;
  564. X
  565. X   index2 = 0;
  566. X
  567. X/* Count the number of segments left, set their endpoints to be valid */
  568. X
  569. X   for(index = 0; index < segment; index++){
  570. X      if(segments[index].valid){
  571. X         segments[index].p->valid = 1;
  572. X         segments[index].q->valid = 1;
  573. X         index2++;
  574. X         }
  575. X      }
  576. X
  577. X/* Count the number of points left */
  578. X
  579. X   count = 0;
  580. X
  581. X   for(index = 0; index < point; index++){
  582. X      if(points[index].valid){
  583. X         points[index].index = count++;
  584. X         }
  585. X      }
  586. X
  587. X   *numPoints = count;
  588. X   *numSegments = index2;
  589. X}
  590. X
  591. X
  592. X
  593. XwriteObject(filename, point, segment, numPoints, numSegments)
  594. Xchar *filename;
  595. Xint point, segment, numPoints, numSegments;
  596. X/*****************************************************************************
  597. X    Write the object to a file.
  598. X*****************************************************************************/
  599. X{
  600. XFILE *fd;
  601. Xint index;
  602. X
  603. X   fd = stdout;
  604. X
  605. X   if((strcmp(filename, "-")) && ((fd = fopen(filename, "w")) == NULL)){
  606. X      fprintf(stderr, "Unable to open file: %s\n", filename);
  607. X      exit(1);
  608. X      }
  609. X
  610. X   fprintf(fd, "%d %d\n", numPoints, numSegments);
  611. X
  612. X   for(index = 0; index < point; index++){
  613. X      if(points[index].valid){
  614. X         fprintf(fd, "%d %d %d\n", points[index].x, points[index].y,
  615. X            points[index].z);
  616. X      }
  617. X      }
  618. X   
  619. X   for(index = 0; index < segment; index++){
  620. X      if(segments[index].valid)
  621. X         fprintf(fd,"%d %d\n", segments[index].p->index,
  622. X         segments[index].q->index);
  623. X      }
  624. X
  625. X   fclose(fd);
  626. X}
  627. X
  628. X
  629. X
  630. Xmain(argc, argv)
  631. Xint argc;
  632. Xchar **argv;
  633. X/*****************************************************************************
  634. X   Attempt to read in a list of segments and generate an optimized
  635. X   object file for them.
  636. X*****************************************************************************/
  637. X{
  638. Xfloat scale;
  639. Xint point, segment, numPoints, numSegments, index, inSet, outSet;
  640. Xchar *inFile, *outFile;
  641. X
  642. X   scale = 1.0;
  643. X
  644. X   inSet = 0;
  645. X   outSet = 0;
  646. X
  647. X   for(index = 1; index < argc; index++){
  648. X      if(!(strcmp("-scale", argv[index]))){
  649. X         if((sscanf(argv[++index], "%f", &scale)) != 1){
  650. X            fprintf(stderr, "Bad scale value\n");
  651. X            exit(1);
  652. X            }
  653. X      }else{
  654. X         if(!inSet){
  655. X            inSet = 1;
  656. X            inFile = argv[index];
  657. X         }else{
  658. X            outSet = 1;
  659. X            outFile = argv[index];
  660. X            }
  661. X         }
  662. X      }
  663. X  
  664. X   if((!inSet) || (!outSet)){
  665. X      fprintf(stderr, "Usage: %s [-scale <value>] <infile> <outfile>\n",
  666. X      argv[0]);
  667. X      fprintf(stderr, "Use - for standard input or output\n");
  668. X      fprintf(stderr, "%s converts a list of segments to .obj format\n",
  669. X      argv[0]);
  670. X      exit(1);
  671. X      }
  672. X
  673. X   readSegments(inFile, scale, &point, &segment);
  674. X   eliminateDuplicates(point, segment, &numPoints, &numSegments);
  675. X   writeObject(outFile, point, segment, numPoints, numSegments);
  676. X}
  677. END_OF_FILE
  678. if test 17970 -ne `wc -c <'con/con.c'`; then
  679.     echo shar: \"'con/con.c'\" unpacked with wrong size!
  680. fi
  681. # end of 'con/con.c'
  682. fi
  683. if test -f 'constants.h' -a "${1}" != "-c" ; then 
  684.   echo shar: Will not clobber existing file \"'constants.h'\"
  685. else
  686. echo shar: Extracting \"'constants.h'\" \(2423 characters\)
  687. sed "s/^X//" >'constants.h' <<'END_OF_FILE'
  688. X
  689. X/*
  690. X  Copyright 1992 Mark Spychalla
  691. X
  692. X  Permission to use, copy, modify, distribute, and sell this software and
  693. X  its documentation for any purpose is hereby granted without fee,
  694. X  provided that the above copyright notice appear in all copies and that
  695. X  both that copyright notice and this permission notice appear in
  696. X  supporting documentation, and that the name of Mark Spychalla not be used
  697. X  in advertising or publicity pertaining to distribution of the software
  698. X  without specific, written prior permission.  Mark Spychalla makes no
  699. X  representations about the suitability of this software for any purpose.
  700. X  It is provided "as is" without express or implied warranty.
  701. X
  702. X  Mark Spychalla disclaims all warranties with regard to this software,
  703. X  including all implied warranties of merchantability and fitness, in no
  704. X  event shall Mark Spychalla be liable for any special, indirect or
  705. X  consequential damages or any damages whatsoever resulting from loss of use,
  706. X  data or profits, whether in an action of contract, negligence or other
  707. X  tortious action, arising out of or in connection with the use or performance
  708. X  of this software.
  709. X*/
  710. X
  711. X#define INFINITY 8192 
  712. X
  713. X#define RClipWithRight   6
  714. X#define RClipWithLeft    5 
  715. X
  716. X#define PointBehind      4 
  717. X
  718. X#define BClipWithRight   3 
  719. X#define BClipWithLeft    2 
  720. X
  721. X#define ClipWithRight    3 
  722. X#define ClipWithLeft     2 
  723. X
  724. X#define ClipWithBottom   1 
  725. X#define ClipWithTop      0 
  726. X
  727. X#define RRight     (1 << RClipWithRight) 
  728. X#define RLeft      (1 << RClipWithLeft) 
  729. X
  730. X#define Behind     (1 << PointBehind)  
  731. X
  732. X#define BRight     (1 << BClipWithRight) 
  733. X#define BLeft      (1 << BClipWithLeft) 
  734. X
  735. X#define Right      (1 << ClipWithRight) 
  736. X#define Left       (1 << ClipWithLeft) 
  737. X
  738. X#define Bottom     (1 << ClipWithBottom) 
  739. X#define Top        (1 << ClipWithTop)  
  740. X
  741. X#define Bmask      (~BRight & ~BLeft) 
  742. X#define Rmask      (~RRight & ~RLeft) 
  743. X#define RBmask     (Rmask & Bmask) 
  744. X#define RLeftRight (RRight | RLeft) 
  745. X
  746. X#define MAXMEM          524288
  747. X#define NUMSEGMENTS     12000
  748. X#define NUMCOLORS       256
  749. X#define COLOROFFSET     240
  750. X#define BLOCKCOUNT      100000
  751. X#define TMPSTRLEN       16
  752. X#define SMALLMOVEMENT   40000
  753. X#define POINTERRATIO    0.007 
  754. X#define MARGIN          30
  755. X#define xOffset         3
  756. X#define yOffset         3
  757. X#define NUMCOLS         132
  758. X#define NUMROWS         55 
  759. X#define XLENGTH         60
  760. X#define YLENGTH         120
  761. X#define GAPFACTOR       1.6
  762. X#define TWOPI        6.2831853
  763. END_OF_FILE
  764. if test 2423 -ne `wc -c <'constants.h'`; then
  765.     echo shar: \"'constants.h'\" unpacked with wrong size!
  766. fi
  767. # end of 'constants.h'
  768. fi
  769. if test -f 'gi.h' -a "${1}" != "-c" ; then 
  770.   echo shar: Will not clobber existing file \"'gi.h'\"
  771. else
  772. echo shar: Extracting \"'gi.h'\" \(3176 characters\)
  773. sed "s/^X//" >'gi.h' <<'END_OF_FILE'
  774. X
  775. X/*
  776. X  Copyright 1992 Mark Spychalla
  777. X
  778. X  Permission to use, copy, modify, distribute, and sell this software and
  779. X  its documentation for any purpose is hereby granted without fee,
  780. X  provided that the above copyright notice appear in all copies and that
  781. X  both that copyright notice and this permission notice appear in
  782. X  supporting documentation, and that the name of Mark Spychalla not be used
  783. X  in advertising or publicity pertaining to distribution of the software
  784. X  without specific, written prior permission.  Mark Spychalla makes no
  785. X  representations about the suitability of this software for any purpose.
  786. X  It is provided "as is" without express or implied warranty.
  787. X
  788. X  Mark Spychalla disclaims all warranties with regard to this software,
  789. X  including all implied warranties of merchantability and fitness, in no
  790. X  event shall Mark Spychalla be liable for any special, indirect or
  791. X  consequential damages or any damages whatsoever resulting from loss of use,
  792. X  data or profits, whether in an action of contract, negligence or other
  793. X  tortious action, arising out of or in connection with the use or performance
  794. X  of this software.
  795. X*/
  796. X
  797. X#include <X11/Xlib.h>
  798. X#include <X11/Xatom.h>
  799. X#include <X11/Xutil.h>
  800. X#include <X11/X.h>
  801. X#include "constants.h"
  802. X#include "types.h"
  803. X#include "macros.h"
  804. X#include <math.h>
  805. X
  806. X/* Graphics interface error codes */
  807. X
  808. X#define GIE_OK             0    /* No error                      */
  809. X#define NO_CONNECT        -1    /* Unable to connect with server */ 
  810. X#define NO_CREATE_WINDOW    -2    /* Unable to create window       */
  811. X#define NO_CREATE_GC        -3    /* Unable to create gc           */
  812. X#define NO_CREATE_COLORMAP    -4    /* Unable to create colormap     */
  813. X#define GIE_LASTERRNO        -5    /* Last errno */
  814. X
  815. Xextern int GIerrno;
  816. X
  817. X
  818. X/* PROTOTYPES */
  819. X
  820. X#ifdef PROTOTYPES
  821. X
  822. Xextern char *allocate(int bytes);
  823. X
  824. Xextern int clipSegment(number *pX, number *pY, number *qX, number *qY,
  825. Xint Pclip, int Qclip, number H, number V);
  826. X
  827. Xextern void clip(segment *segments, int numSegments, GIinfo *gi);
  828. X
  829. Xextern void rotate(point *points, int numPoints, ObjectInfo *obj,
  830. Xnumber H, number V); 
  831. X
  832. Xextern void readObjectFile(char *filename, int *numPoints, int *numSegments,
  833. Xpoint **points, segment **segments, double scale);
  834. X
  835. Xextern void GI_ParseCommandLine(int argc, char *argv[], char **filename,
  836. Xdouble *scale, GIinfo *gi);
  837. X
  838. Xextern void GI_ResizeFont(GIinfo *gi);
  839. X
  840. Xextern void GI_PrintString(char *string, GIinfo *gi);
  841. X
  842. Xextern void GI_DisplayMenu(GIinfo *gi);
  843. X
  844. Xextern void GI_ResetPurpleRectangle(int XL, int YL, int XH, int YH, GIinfo *gi);
  845. X
  846. Xextern int GI_InitDisplay(GIinfo *gi, int numSegments);
  847. X
  848. Xextern void GI_MakeImageCurrent(GIinfo *gi);
  849. X
  850. Xextern int GI_CheckEvent(Display *display, XEvent *event, char *arg);
  851. X
  852. Xextern void GI_GetInput(int *pointerX, int *pointerY, char *command,
  853. Xint *same, GIinfo *gi);
  854. X
  855. Xextern void GI_UpdatePosition(ObjectInfo *obj, GIinfo *gi);
  856. X
  857. Xextern void GI_PrintError(char *errString);
  858. X
  859. Xextern void GI_Rotate(anglePoint *points, double cx, double cy, double cz,
  860. Xdouble sx, double sy, double sz);
  861. X
  862. Xextern double GI_DotProduct(double x1, double Y1, double x2, double y2);
  863. X
  864. Xextern void GI_CalculateAngles(double *X, double *Y, double *Z, double X1,
  865. Xdouble Y1, double Z1);
  866. X
  867. X#endif
  868. END_OF_FILE
  869. if test 3176 -ne `wc -c <'gi.h'`; then
  870.     echo shar: \"'gi.h'\" unpacked with wrong size!
  871. fi
  872. # end of 'gi.h'
  873. fi
  874. echo shar: End of archive 6 \(of 6\).
  875. cp /dev/null ark6isdone
  876. MISSING=""
  877. for I in 1 2 3 4 5 6 ; do
  878.     if test ! -f ark${I}isdone ; then
  879.     MISSING="${MISSING} ${I}"
  880.     fi
  881. done
  882. if test "${MISSING}" = "" ; then
  883.     echo You have unpacked all 6 archives.
  884.     rm -f ark[1-9]isdone
  885. else
  886.     echo You still need to unpack the following archives:
  887.     echo "        " ${MISSING}
  888. fi
  889. ##  End of shell archive.
  890. exit 0
  891. -- 
  892. Molecular Simulations, Inc.             mail: dcmartin@msi.com
  893. 796 N. Pastoria Avenue                  uucp: uunet!dcmartin
  894. Sunnyvale, California 94086             at&t: 408/522-9236
  895.