Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/matc/src/elmer/gra.h
3203 views
1
/*
2
* Graphics primitives are loaded dynamically to a global
3
* array of functions. To make a graphics driver to a specific
4
* device one has to make the following functions (named differently
5
* of course) and edit routine gra_init to load these functions
6
* to array of functions when the device is selected.
7
*
8
* gra_open(dev_ident, output_device)
9
* - initialize the device to accept graphics commands
10
*
11
* gra_close()
12
* - deallocate device
13
*
14
* gra_clear()
15
* - clear screen (current viewport area)
16
*
17
* gra_flush()
18
* - flush output buffers, if device have such
19
*
20
* gra_defcolor(int index, double r, double g, double b)
21
* - define entry in color map
22
*
23
* gra_color(int index)
24
* - select a color from map to be used by following graphics commands
25
*
26
* gra_polyline(int n, Point *points)
27
* - draw a line between points given
28
*
29
* gra_draw(Point *point)
30
* - draw a line from current point to a point given
31
*
32
* gra_move(Point *point)
33
* - move current point to point given
34
*
35
* gra_text(height, char *str)
36
* - text beginning from current point
37
*
38
* gra_polymarker(int index, int n, Point *points)
39
* - draw a marker to points given
40
*
41
* gra_marker(int index, Point *point)
42
* - draw a marker to point given
43
*
44
* gra_areafill(int n, Point *points)
45
* - polygon filling
46
*
47
* gra_image(int width, int height, int depth, int *raster)
48
* - raster plotting
49
*
50
* provided by the library are (but if your device supports these,
51
* include them in the driver if you like).
52
*
53
* gra_window(double xl, xh, yl, yh, zl, zh);
54
* gra_viewport(double wx, wy, wz, *vx, *vy);
55
* gra_setmatrix(GMATRIX gm) (4 x 4 transf. matrix)
56
* gra_getmatrix(GMATRIX gm)
57
* gra_rotate(double x, y, z);
58
* gra_scale(double x, y, z);
59
* gra_translate(double x, y, z);
60
*
61
* following functions can be used as needed:
62
*
63
* gra_window_to_viewport(double x, y, z, *xs, *ys);
64
* gra_transm(double xw, yw, zw, xc, yc, zc);
65
*/
66
67
68
/*
69
* $Id: gra.h,v 1.1.1.1 2005/04/14 13:29:14 vierinen Exp $
70
*
71
* $Log: gra.h,v $
72
* Revision 1.1.1.1 2005/04/14 13:29:14 vierinen
73
* initial matc automake package
74
*
75
* Revision 1.2 1998/08/01 12:34:41 jpr
76
*
77
* Added Id, started Log.
78
*
79
*
80
*/
81
82
#define CL_XMIN -1
83
#define CL_XMAX 1
84
#define CL_YMIN -1
85
#define CL_YMAX 1
86
87
#define GRA_DRV_NULL 0
88
/* #define GRA_DRV_IRIS 1 */
89
/* #define GRA_DRV_DISSPLA 2 */
90
/* #define GRA_DRV_TEKLIB 3 */
91
#define GRA_DRV_PS 4
92
93
/*
94
* transformation matrix type
95
*/
96
typedef double GMATRIX[4][4];
97
98
typedef struct
99
{
100
double xlow, xhigh, ylow, yhigh;
101
} matc_Rectangle;
102
103
typedef struct
104
{
105
double x, y, z;
106
} Point;
107
108
typedef struct
109
{
110
FILE *out_fp;
111
int driver;
112
113
struct
114
{
115
double xlow, xhigh, ylow, yhigh, zlow, zhigh;
116
} window;
117
118
matc_Rectangle viewport;
119
120
GMATRIX modelm;
121
GMATRIX viewm;
122
GMATRIX projm;
123
GMATRIX transfm;
124
double pratio;
125
126
Point cur_point;
127
int cur_color;
128
int cur_marker;
129
130
} G_STATE;
131
132
#ifdef MODULE_MATC
133
G_STATE gra_state =
134
{
135
NULL, GRA_DRV_NULL, /* out_fp, driver */
136
-1.0, 1.0, -1.0, 1.0, -1.0, 1.0, /* window */
137
0.0, 1.0, 0.0, 1.0, /* viewport */
138
1.0, 0.0, 0.0, 0.0, /* model transformation matrix */
139
0.0, 1.0, 0.0, 0.0,
140
0.0, 0.0, 1.0, 0.0,
141
0.0, 0.0, 0.0, 1.0,
142
1.0, 0.0, 0.0, 0.0, /* viewing transformation matrix */
143
0.0, 1.0, 0.0, 0.0,
144
0.0, 0.0, 1.0, 0.0,
145
0.0, 0.0, 0.0, 1.0,
146
1.0, 0.0, 0.0, 0.0, /* projection transformation matrix */
147
0.0, 1.0, 0.0, 0.0,
148
0.0, 0.0, 1.0, 0.0,
149
0.0, 0.0, 0.0, 1.0,
150
1.0, 0.0, 0.0, 0.0, /* total transformation matrix */
151
0.0, 1.0, 0.0, 0.0,
152
0.0, 0.0, 1.0, 0.0,
153
0.0, 0.0, 0.0, 1.0,
154
0.0, /* perspective ratio */
155
0.0,0.0, /* cur_point */
156
1, 1 /* cur_color, cur_marker */
157
};
158
#else
159
EXT G_STATE gra_state;
160
#endif
161
162
#define GRA_FUNCS 27
163
164
#define G_OPEN 0
165
#define G_CLOSE 1
166
#define G_CLEAR 2
167
#define G_VIEWPORT 3
168
#define G_WINDOW 4
169
#define G_DEFCOLOR 5
170
#define G_COLOR 6
171
#define G_POLYLINE 7
172
#define G_DRAW 8
173
#define G_MOVE 9
174
#define G_POLYMARKER 10
175
#define G_MARKER 11
176
#define G_AREAFILL 12
177
#define G_IMAGE 13
178
#define G_TEXT 14
179
#define G_FLUSH 15
180
#define G_RESET 16
181
#define G_TRANSLATE 17
182
#define G_ROTATE 18
183
#define G_SCALE 19
184
#define G_VIEWPOINT 20
185
#define G_GETMATRIX 21
186
#define G_SETMATRIX 22
187
#define G_PERSPECTIVE 23
188
#define G_DBUFFER 24
189
#define G_SBUFFER 25
190
#define G_SWAPBUF 26
191
192
#ifdef MODULE_MATC
193
void (*gra_funcs[GRA_FUNCS])() =
194
{
195
gra_error, gra_error, gra_error, gra_error, gra_error,
196
gra_error, gra_error, gra_error, gra_error, gra_error,
197
gra_error, gra_error, gra_error, gra_error, gra_error,
198
gra_error, gra_error, gra_error, gra_error, gra_error,
199
gra_error, gra_error, gra_error, gra_error, gra_error,
200
gra_error, gra_error
201
};
202
#else
203
EXT void(*gra_funcs[GRA_FUNCS])();
204
#endif
205
206
#define GRA_OPEN(d) ((void (*)(int)) (*gra_funcs[G_OPEN]))(d)
207
#define GRA_CLOSE() ((void (*)(void)) (*gra_funcs[G_CLOSE]))()
208
#define GRA_CLEAR() ((void (*)(void)) (*gra_funcs[G_CLEAR]))()
209
#define GRA_FLUSH() ((void (*)(void)) (*gra_funcs[G_FLUSH]))()
210
#define GRA_RESET() ((void (*)(void)) (*gra_funcs[G_RESET]))()
211
#define GRA_DEFCOLOR(i, r, g, b) ((void (*)(int, double, double, double)) (*gra_funcs[G_DEFCOLOR]))(i, r, g, b)
212
#define GRA_COLOR(i) ((void (*)(int)) (*gra_funcs[G_COLOR]))(i)
213
#define GRA_POLYLINE(n, p) ((void (*)(int, void *)) (*gra_funcs[G_POLYLINE]))(n, p);
214
#define GRA_DRAW(p) ((void (*)(void *)) (*gra_funcs[G_DRAW]))(p)
215
#define GRA_MOVE(p) ((void (*)(void *)) (*gra_funcs[G_MOVE]))(p)
216
#define GRA_POLYMARKER(i, n, p) ((void (*)(int, int, void *)) (*gra_funcs[G_POLYMARKER]))(i, n, p)
217
#define GRA_MARKER(i, p) ((void (*)(int, void *)) (*gra_funcs[G_MARKER]))(i, p)
218
#define GRA_AREAFILL(n, p) ((void (*)(int, void *)) (*gra_funcs[G_AREAFILL]))(n, p)
219
#define GRA_IMAGE(w,h,d,r) ((void (*)(int, int, int, void *)) (*gra_funcs[G_IMAGE]))(w,h,d,r)
220
#define GRA_TEXT(h,r,s) ((void (*)(double, double, char *)) (*gra_funcs[G_TEXT]))(h,r,s)
221
#define GRA_TRANSLATE(x,y,z) ((void (*)(double, double, double)) (*gra_funcs[G_TRANSLATE]))(x,y,z)
222
#define GRA_ROTATE(x,y,z) ((void (*)(double, double, double)) (*gra_funcs[G_ROTATE]))(x,y,z)
223
#define GRA_SCALE(x,y,z) ((void (*)(double, double, double)) (*gra_funcs[G_SCALE]))(x,y,z)
224
#define GRA_VIEWPOINT(xf,yf,zf,xt,yt,zt) ((void (*)(double, double, double, double, double, double)) (*gra_funcs[G_VIEWPOINT]))(xf,yf,zf,xt,yt,zt)
225
#define GRA_GETMATRIX(gm) ((void (*)(void *)) (*gra_funcs[G_GETMATRIX]))(gm)
226
#define GRA_SETMATRIX(gm) ((void (*)(void *)) (*gra_funcs[G_SETMATRIX]))(gm)
227
#define GRA_DBUFFER(gm) ((void (*)(void *)) (*gra_funcs[G_DBUFFER]))(gm)
228
#define GRA_SBUFFER(gm) ((void (*)(void *)) (*gra_funcs[G_SBUFFER]))(gm)
229
#define GRA_SWAPBUF(gm) ((void (*)(void *)) (*gra_funcs[G_SWAPBUF]))(gm)
230
#define GRA_WINDOW(x1,x2,y1,y2,z1,z2) ((void (*)(double, double, double, double, double, double)) (*gra_funcs[G_WINDOW]))(x1,x2,y1,y2,z1,z2)
231
#define GRA_VIEWPORT(x1,x2,y1,y2) ((void (*)(double, double, double, double)) (*gra_funcs[G_VIEWPORT]))(x1,x2,y1,y2)
232
#define GRA_PERSPECTIVE(r) ((void (*)(double)) (*gra_funcs[G_PERSPECTIVE]))(r)
233
234