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