ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/cgraph.c
Revision: 1.1
Committed: Sat Feb 22 02:07:26 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * cgraph.c - routines for sending graphs to tty's.
6 *
7 * Greg Ward
8 * 7/7/86
9 */
10
11
12 #include <stdio.h>
13
14 #include "mgvars.h"
15
16
17 #define FHUGE 1e10
18
19 #define MAXSIZE 10000 /* Maximum size in characters of output */
20
21 extern char *progname; /* argv[0] */
22
23 static char outcarr[MAXSIZE]; /* character output array */
24
25 static double xmin = XMAX, xmax = XMIN, /* extrema */
26 ymin = YMAX, ymax = YMIN;
27
28 static int dwidth, dlength; /* device width and length */
29
30 static int nplottable; /* number of plottable points */
31
32
33 cgraph(width, length) /* do a character graph to stdout */
34 int width, length;
35 {
36 if (width * length > MAXSIZE) {
37 fprintf(stderr, "%s: page too big\n", progname);
38 quit(1);
39 }
40 dwidth = width;
41 dlength = length;
42 climits(); /* get min & max values */
43 cplot(); /* do character plot */
44 }
45
46
47 climits() /* get min & max values */
48 {
49 int i, cstretch();
50
51 xmin = gparam[XMIN].flags & DEFINED ?
52 varvalue(gparam[XMIN].name) :
53 FHUGE ;
54 xmax = gparam[XMAX].flags & DEFINED ?
55 varvalue(gparam[XMAX].name) :
56 -FHUGE ;
57 ymin = gparam[YMIN].flags & DEFINED ?
58 varvalue(gparam[YMIN].name) :
59 FHUGE ;
60 ymax = gparam[YMAX].flags & DEFINED ?
61 varvalue(gparam[YMAX].name) :
62 -FHUGE ;
63
64 nplottable = 0;
65 for (i = 0; i < MAXCUR; i++)
66 mgcurve(i, cstretch);
67
68 if (nplottable == 0) {
69 fprintf(stderr, "%s: no plottable data\n", progname);
70 quit(1);
71 }
72 printf("XMIN= %f XMAX= %f YMIN= %f YMAX= %f\n",
73 xmin, xmax, ymin, ymax);
74 }
75
76
77 cstretch(c, x, y) /* stretch our boundaries */
78 int c;
79 double x, y;
80 {
81 if (gparam[XMIN].flags & DEFINED &&
82 x < xmin)
83 return;
84 if (gparam[XMAX].flags & DEFINED &&
85 x > xmax)
86 return;
87 if (gparam[YMIN].flags & DEFINED &&
88 y < ymin)
89 return;
90 if (gparam[YMAX].flags & DEFINED &&
91 y > ymax)
92 return;
93
94 if (x < xmin)
95 xmin = x;
96 if (x > xmax)
97 xmax = x;
98 if (y < ymin)
99 ymin = y;
100 if (y > ymax)
101 ymax = y;
102
103 nplottable++;
104 }
105
106
107 cplot() /* do character plot */
108 {
109 int cpoint();
110 int i, j;
111 register char *op;
112
113 for (op = outcarr+dlength*dwidth; op > outcarr; )
114 *--op = ' ';
115
116 for (i = 0; i < MAXCUR; i++)
117 mgcurve(i, cpoint);
118
119 for (i = 0; i < dlength; i++) {
120 for (j = 0; j < dwidth; j++)
121 putchar(*op++);
122 putchar('\n');
123 }
124 }
125
126
127 cpoint(c, x, y) /* store a point */
128 int c;
129 double x, y;
130 {
131 register int ndx;
132
133 if (x < xmin || x > xmax || y < ymin || y > ymax)
134 return;
135
136 ndx = (dlength-1)*(1.0 - (y - ymin)/(ymax - ymin)) + 0.5;
137 ndx = dwidth*ndx + (dwidth-1)*(x-xmin)/(xmax-xmin) + 0.5;
138
139 if (outcarr[ndx] == ' ')
140 outcarr[ndx] = c+'A';
141 else if (outcarr[ndx] > '1' && outcarr[ndx] < '9')
142 outcarr[ndx]++;
143 else if (outcarr[ndx] == '9')
144 outcarr[ndx] = '*';
145 else if (outcarr[ndx] != '*')
146 outcarr[ndx] = '2';
147 }