Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical ALgorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2010, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
#define view3D
37
38
39
#include <X11/Xlib.h>
40
#include <X11/Xresource.h>
41
#include <X11/Xutil.h>
42
#include <setjmp.h>
43
44
#include "hash.h"
45
46
#include "view.h"
47
48
49
#include "view3D.h"
50
#include "actions.h"
51
#include "viewCommand.h"
52
#include "XDefs.h"
53
#include "override.h"
54
#include "G.h" /* Gdraw functions header file */
55
56
/**********************************/
57
/*** axes stuff ***/
58
/**********************************/
59
60
#define viewportCreateMASK CWBackPixel | CWBorderPixel | CWEventMask | CWCursor | CWColormap
61
#define viewportTitleCreateMASK CWBackPixel | CWBorderPixel | CWCursor | CWColormap | CWEventMask | CWOverrideRedirect
62
#define carefullySetFont(gc,font) if (font != serverFont) XSetFont(dsply,gc,font->fid)
63
64
#define viewportMASK (KeyPressMask + ButtonPressMask + ExposureMask)
65
#define titleMASK (ExposureMask)
66
67
#define lineWidth 1
68
#define lineHeight 1
69
70
#define titleColor monoColor(36)
71
#define titleHeight 24
72
#define appendixHeight 0
73
74
#define viewWidth 400
75
#define viewHeight 400
76
#define viewYmax vwInfo.height
77
#define viewYmin vwInfo.y
78
#define viewXmax vwInfo.width
79
#define viewXmin vwInfo.x
80
81
#define GC9991 ((GC)9991)
82
83
84
/* For smooth shading buffers. Should be screen resolution size,
85
and one for each of screen width and height may be needed, or
86
it can be changed dynamically if desired. */
87
88
#ifdef RIOSplatform
89
#define ARRAY_WIDTH 1280 + 1 /* DisplayWidth(dsply,scrn) */
90
#define ARRAY_HEIGHT 1024 + 1 /* DisplayHeight(dsply,scrn) */
91
#else
92
#define ARRAY_WIDTH 1300 /* DisplayWidth(dsply,scrn) */
93
#define ARRAY_HEIGHT 1100 /* DisplayHeight(dsply,scrn) */
94
#endif
95
96
#define viewBorderWidth 0 /* make sure ps.h (postscript header) is the same */
97
98
#define initDeltaX 0.0
99
#define initDeltaY 0.0
100
#define initTheta pi_half/2.0
101
#define initPhi -pi_half/2.0
102
103
#define maxDeltaX 1500.0
104
#define maxDeltaY 1500.0
105
#define minScale 0.01
106
#define maxScale 1000.0
107
108
#define rotateFactor 0.2
109
#define scaleFactor 0.2
110
#define translateFactor 8
111
112
#define viewCursorForeground monoColor(166)
113
#define viewCursorBackground monoColor(5)
114
115
#define axesColor 52
116
#define buttonColor 120
117
#define labelColor 12
118
119
/**********************************/
120
/*** graph stuff ***/
121
/**********************************/
122
123
#define graphBarLeft 76
124
#define graphBarTop 180
125
#define graphBarWidth graphFont->max_bounds.width + 5
126
#define graphBarHeight graphFont->max_bounds.ascent + graphFont->max_bounds.descent
127
#define graphBarDefaultColor monoColor(85)
128
#define graphBarShowingColor monoColor(45)
129
#define graphBarHiddenColor monoColor(146)
130
#define graphBarSelectColor monoColor(45)
131
#define graphBarNotSelectColor monoColor(145)
132
133
/******************************/
134
/*** colors ***/
135
/******************************/
136
137
#define totalHuesConst 27
138
139
#define hueEnd 360
140
141
#undef hueStep
142
#define hueStep (hueEnd/totalHuesConst)
143
144
#define black BlackPixel(dsply,scrn)
145
#define white WhitePixel(dsply,scrn)
146
#define numPlanes 1
147
#define numColors 10
148
#define startColor 0
149
#define maxColors (DisplayCells(dsply,scrn)-1)
150
#define maxPlanes (DefaultVisual((dpy),(scr))->bits_per_rgb)
151
152
/**********************************/
153
/*** Screen and Window Sizes */
154
/**********************************/
155
156
#define physicalWidth DisplayWidth(dsply,scrn)
157
#define physicalHeight DisplayHeight(dsply,scrn)
158
#define deep DisplayPlanes(dsply,scrn)
159
160
#define basicScreen 19
161
162
#define yes 1
163
#define no 0
164
165
#define pi_half 1.57079632
166
#define pi 3.14159265
167
#define three_pi_halves 4.71238898
168
#define two_pi 6.28318530
169
#define pi_sq 9.86960440
170
171
#define degrees_in_two_pi 57
172
#define d2Pi 57
173
174
#define nbuckets 128
175
176
177
#define anywhere 0
178
179
#ifdef DEBUG
180
#include "eventnames.h"
181
#endif
182
183
#define intSize sizeof(int)
184
#define floatSize sizeof(float)
185
186
/* Types so far are X, PS */
187
#define drawViewport(type) { drawPreViewport(type); drawTheViewport(type); }
188
#define spadDrawViewport() spadMode++; drawTheViewport(X); spadMode--;
189
190
191
/********************************/
192
/*** lighting panel ***/
193
/********************************/
194
195
/* These are the lighting panel buttons, they start at 101
196
(numbers less than 101 are reserved for control panel buttons */
197
198
/* From ../include/actions.h */
199
200
#define lightingButtonsStart controlButtonsEnd3D
201
202
#define lightMove (lightingButtonsStart)
203
#define lightMoveXY (lightingButtonsStart+1)
204
#define lightMoveZ (lightingButtonsStart+2)
205
#define lightAbort (lightingButtonsStart+3)
206
#define lightReturn (lightingButtonsStart+4)
207
#define lightTranslucent (lightingButtonsStart+5)
208
209
#define maxlightingButtons 6
210
#define lightingButtonsEnd (lightingButtonsStart + maxlightingButtons)
211
212
/***********************************/
213
/*** view volume panel ***/
214
/***********************************/
215
216
/* These are the volume panel buttons, they start at 200
217
(numbers less than 101 are reserved for control panel buttons */
218
219
#define volumeButtonsStart lightingButtonsEnd
220
221
#define volumeReturn (volumeButtonsStart)
222
#define frustrumBut (volumeButtonsStart+1)
223
#define clipXBut (volumeButtonsStart+2)
224
#define clipYBut (volumeButtonsStart+3)
225
#define clipZBut (volumeButtonsStart+4)
226
#define perspectiveBut (volumeButtonsStart+5)
227
#define clipRegionBut (volumeButtonsStart+6)
228
#define clipSurfaceBut (volumeButtonsStart+7)
229
#define volumeAbort (volumeButtonsStart+8)
230
231
#define maxVolumeButtons 9
232
#define volumeButtonsEnd (volumeButtonsStart + maxVolumeButtons)
233
234
/**** quit panel ****/
235
236
#define quitButtonsStart volumeButtonsEnd
237
238
#define quitAbort (quitButtonsStart)
239
#define quitReturn (quitButtonsStart+1)
240
#define maxQuitButtons 2
241
#define quitButtonsEnd (quitButtonsStart + maxQuitButtons)
242
243
/**** save panel ****/
244
245
#define saveButtonsStart quitButtonsEnd
246
247
#define saveExit (saveButtonsStart)
248
#define pixmap (saveButtonsStart+1)
249
#define ps (saveButtonsStart+2)
250
#define maxSaveButtons 3
251
#define saveButtonsEnd (saveButtonsStart + maxSaveButtons)
252
253
/******************************************/
254
/*** buttons to be allocated ***/
255
/******************************************/
256
257
#define maxButtons3D saveButtonsEnd
258
259
260
/************************ Type Declarations *************************/
261
262
/**********************************/
263
/*** control stuff ***/
264
/**********************************/
265
266
typedef struct _buttonStruct {
267
int buttonKey, pot, mask;
268
short buttonX, buttonY, buttonWidth, buttonHeight, xHalf, yHalf;
269
Window self;
270
const char* text;
271
int textColor,textHue,textShade;
272
} buttonStruct;
273
274
typedef struct _controlPanelStruct {
275
Window controlWindow, messageWindow, colormapWindow;
276
char message[40];
277
buttonStruct buttonQueue[maxButtons3D];
278
} controlPanelStruct;
279
280
typedef struct _mouseCoord {
281
float x, y;
282
} mouseCoord;
283
284
285
/**********************************/
286
/*** mesh stuff ***/
287
/**********************************/
288
289
typedef struct _meshStruct {
290
float N0[4], N1[4]; /* the fourth element is Zmin */
291
} meshStruct;
292
293
typedef struct _points3D {
294
float xmin, xmax,
295
ymin, ymax,
296
xstep, ystep,
297
zmin, zmax,
298
scaleToView;
299
float *zPoints;
300
int xnum, ynum,
301
nextRow,
302
style;
303
meshStruct *normData; /* list of normals */
304
} points3D;
305
306
307
308
typedef struct _colorBuffer {
309
int indx;
310
char axes;
311
} colorBuffer;
312
313
314
/**********************************/
315
/*** axes stuff ***/
316
/**********************************/
317
318
typedef struct _point {
319
float x, y, z;
320
int flag;
321
} point;
322
323
324
/**** one of the (many) sloppy things that need to be
325
cleaned up is the viewPoints structure. a lot of
326
stuff in it is used solely for the function of
327
two variables stuff. they should be moved to
328
the fun2Var substructure. ****/
329
330
typedef struct _viewPoints {
331
int viewportKey;
332
char title[80];
333
Window viewWindow, titleWindow;
334
float deltaX, deltaY,
335
scale, scaleX, scaleY, scaleZ,
336
theta, phi,
337
deltaX0, deltaY0, /* initial values */
338
scale0, transX, transY, transZ, thetaObj, phiObj,
339
theta0, phi0, theta1, phi1, axestheta, axesphi;
340
float deltaZ, deltaZ0;
341
controlPanelStruct *controlPanel;
342
int axesOn, regionOn, monoOn;
343
int zoomXOn, zoomYOn, zoomZOn;
344
int originrOn, objectrOn;
345
int xyOn, xzOn, yzOn;
346
int originFlag;
347
int justMadeControl, haveControl,
348
closing, allowDraw, needNorm;
349
points3D meshData;
350
float lightVector[3], translucency;
351
int hueOffset, numberOfHues, hueTop, diagonals;
352
struct _viewPoints *prevViewport, *nextViewport;
353
} viewPoints;
354
355
356
typedef struct _controlXY {
357
int putX, putY;
358
} controlXY;
359
360
361
362
/************************** Bitmap Files ***************************/
363
#if 0
364
#include "../include/purty/mouse11.bitmap"
365
#include "../include/purty/mouse11.mask"
366
#include "../include/purty/spadBitmap.bitmap"
367
#include "../include/purty/spadMask.mask"
368
#include "../include/purty/light11.bitmap"
369
#include "../include/purty/light11.mask"
370
#endif
371
372
373
/******* useful definitions *******/
374
375
#define CONTROLpanel 1
376
#define LIGHTpanel 2
377
#define VOLUMEpanel 3
378
#define CONTOURpanel 4
379
#define QUITpanel 5
380
#define SAVEpanel 6
381
382
#define machine0 0.0002
383
384
#include "globals.h"
385
386
387