1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
|
/*
Copyright (C) 1991-2002, The Numerical ALgorithms Group Ltd.
All rights reserved.
Copyright (C) 2007-2008, Gabriel Dos Reis.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Neither the name of The Numerical ALgorithms Group Ltd. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _VIEWPORT3D_C
#include "axiom-c-macros.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "spadBitmap.bitmap"
#include "spadMask.mask"
#include "header.h"
/*** definition for the axes and labels - this is the minimun that will be
drawn on the window - thus allowing the user some idea of the
orientation of the coordinate axes when rotating, etc. The
drawing of the mesh is aborted when an appropriate X event occurs.
The mesh should be scaled to the range of [-100..100] in all
directions. axisRange defines the range...change the stuff below
if that has changed. ***/
#include "static.h"
#include "draw.h"
#include "volume.h"
#include "mode.h"
#include "util.H1"
#include "Gfun.H1"
#include "XSpadFill.H1"
#include "all_3d.H1"
#define axesOffset 5
Atom wm_delete_window;
/***************************
*** void writeTitle() ***
***************************/
void
#ifdef _NO_PROTO
writeTitle ()
#else
writeTitle (void)
#endif
{
int strlength;
XWindowAttributes twInfo;
XGetWindowAttributes(dsply, viewport->titleWindow, &twInfo);
if (mono || viewport->monoOn)
GSetForeground(anotherGC, (float)foregroundColor, Xoption);
else
GSetForeground(anotherGC, (float)titleColor, Xoption);
XClearWindow(dsply, viewport->titleWindow);
strlength = strlen(viewport->title);
GDrawImageString(anotherGC, viewport->titleWindow,
centerX(anotherGC, viewport->title, strlength,
twInfo.width), 15,
viewport->title, strlength, Xoption);
}
/****************************
* void drawPreViewport() *
* *
* draws the axes and boxes *
* before the actual stuff. *
* all incoming signals *
* should be block and no *
* check for pending X *
* events are made. *
* *
****************************/
void
#ifdef _NO_PROTO
drawPreViewport (dFlag)
int dFlag; /* display flag: PS, X, etc. */
#else
drawPreViewport (int dFlag)
#endif
{
int i, j, vPx0, vPy0, vPx1, vPy1;
/* for drawing the box */
float vPz, absTransX, absTransY;
XPoint blackbox[3], line[2];
RGB axes_rgb, clipbox_rgb, boundbox_rgb;
axes_rgb.r = 0.8; axes_rgb.g = 0.6; axes_rgb.b = 0.2;
clipbox_rgb.r = 0.4; clipbox_rgb.g = 0.5; clipbox_rgb.b = 0.9;
boundbox_rgb.r = 0.4; boundbox_rgb.g = 0.7; boundbox_rgb.b = 0.9;
XGetWindowAttributes(dsply, viewport->viewWindow, &vwInfo);
graphWindowAttrib = vwInfo;
/* Calculate various factors for use in projection */
/* Scale so that plot the scaling between the axes remains constant
and fits within the smaller of the two dimensions. */
xCenter = vwInfo.width / 2;
yCenter = vwInfo.height / 2;
if (vwInfo.height <= vwInfo.width) {
viewScale = viewport->scale * vwInfo.height / viewHeight;
}
else {
viewScale = viewport->scale * vwInfo.width / viewWidth;
}
/* Draw the projected image */
/** draw the axes without heeding to X interrupts, first **/
if (dFlag == Xoption) /* do this for X option only */
XClearWindow(dsply, viewport->viewWindow);
sinTheta = sin(-viewport->axestheta);
cosTheta = cos(-viewport->axestheta);
sinPhi = sin(viewport->axesphi);
cosPhi = cos(viewport->axesphi);
/* Create transformation matrices */
ROTATE(R); /* angles theta and phi are global */
SCALE(viewport->scaleX,viewport->scaleY,viewport->scaleZ,S);
TRANSLATE(-viewport->deltaX,-viewport->deltaY,0.0,T);
/**** Pre Draw Routine ****/
if ((dFlag == PSoption) && (foregroundColor == white)) {
GSetForeground(globGC,(float)backgroundColor,dFlag);
blackbox[0].x = vwInfo.width; blackbox[0].y = vwInfo.height;
blackbox[1].x = 0; blackbox[1].y = 0;
blackbox[2].x = 0; blackbox[2].y = vwInfo.height;
if (viewport->monoOn || mono) {
PSFillPolygon(globGC, blackbox, 3);
} else {
PSColorPolygon(0.0,0.0,0.0,blackbox,4);
}
blackbox[0].x = vwInfo.width; blackbox[0].y = 0;
blackbox[1].x = 0; blackbox[1].y = 0;
blackbox[2].x = vwInfo.width; blackbox[2].y = vwInfo.height;
if (viewport->monoOn || mono) {
PSFillPolygon(globGC, blackbox, 3);
} else {
PSColorPolygon(0.0,0.0,0.0,blackbox,4);
}
}
/* axes */
for (i=0; i < 3; i++) {
projectStuff(axes[i][0],axes[i][1],axes[i][2],&vPx0,&vPy0,&vPz);
axesXY[i][0] = vPx0; axesXY[i][1] = vPy0; axesZ[i][0] = vPz;
projectStuff(axes[i][3],axes[i][4],axes[i][5],&vPx1,&vPy1,&vPz);
axesXY[i][2] = vPx1; axesXY[i][3] = vPy1; axesZ[i][1] = vPz;
if (viewport->axesOn) {
if (viewport->monoOn || mono) {
GSetForeground(globalGC1,(float)foregroundColor,dFlag);
GSetForeground(globGC,(float)foregroundColor,dFlag);
GDrawLine(globalGC1,viewport->viewWindow,vPx0,vPy0,vPx1,vPy1,dFlag);
} else {
if (dFlag == PSoption) {
GSetForeground(globGC,(float)foregroundColor,dFlag);
line[0].x = vPx0; line[0].y = vPy0;
line[1].x = vPx1; line[1].y = vPy1;
PSDrawColor(axes_rgb.r,axes_rgb.g,axes_rgb.b,line,2);
} else {
GSetForeground(globalGC1,(float)monoColor(axesColor),dFlag);
GSetForeground(globGC,(float)monoColor(labelColor),dFlag);
GDrawLine(globalGC1,viewport->viewWindow,vPx0,vPy0,vPx1,vPy1,dFlag);
}
}
if (i == 0) {
if (axesXY[0][2] < axesXY[0][0]) vPx1 -= axesOffset;
else vPx1 += axesOffset;
if (axesXY[0][3] < axesXY[0][1]) vPy1 -= axesOffset;
else vPy1 += axesOffset;
if (!viewport->yzOn)
GDrawString(globGC,viewport->viewWindow,vPx1,vPy1,"X",1,dFlag);
} else {
if (i == 1) {
if (axesXY[1][2] < axesXY[1][0]) vPx1 -= axesOffset;
else vPx1 += axesOffset;
if (axesXY[1][3] < axesXY[1][1]) vPy1 -= axesOffset;
else vPy1 += axesOffset;
if (!viewport->xzOn)
GDrawString(globGC,viewport->viewWindow,vPx1,vPy1,"Y",1,dFlag);
} else {
if (axesXY[2][2] < axesXY[2][0]) vPx1 -= axesOffset;
else vPx1 += axesOffset;
if (axesXY[2][3] < axesXY[2][1]) vPy1 -= axesOffset;
else vPy1 += axesOffset;
if (!viewport->xyOn)
GDrawString(globGC,viewport->viewWindow,vPx1,vPy1,"Z",1,dFlag);
}
}
GSetForeground(globalGC1,(float)monoColor(buttonColor),dFlag);
GSetForeground(globGC,(float)monoColor(buttonColor),dFlag);
} /* if viewport->axesOn */
}
viewport->transX = (viewData.xmax + viewData.xmin)/2.0;
viewport->transY = (viewData.ymax + viewData.ymin)/2.0;
viewport->transZ = (viewData.zmax + viewData.zmin)/2.0;
absTransX = absolute(viewport->transX);
absTransY = absolute(viewport->transY);
if ((absTransX > 0.5) || (absTransY > 0.5)) {
if (absTransX > absTransY)
reScale = 50.0 * absTransX / viewData.scaleToView;
else
reScale = 50.0 * absTransY / viewData.scaleToView;
if (reScale < 100.0) reScale = 100.0;
} else {
reScale = 100.0;
}
sinTheta = sin(-viewport->thetaObj);
cosTheta = cos(-viewport->thetaObj);
sinPhi = sin(viewport->phiObj);
cosPhi = cos(viewport->phiObj);
ROTATE1(R1);
if (viewport->originFlag) viewport->originFlag = no;
sinTheta = sin(-viewport->axestheta);
cosTheta = cos(-viewport->axestheta);
sinPhi = sin(viewport->axesphi);
cosPhi = cos(viewport->axesphi);
ROTATE(R);
/* region box */
if (viewData.clipbox) {
clipCorners[0].x = viewData.clipXmin;
clipCorners[0].y = viewData.clipYmin;
clipCorners[0].z = viewData.clipZmin;
clipCorners[1].x = viewData.clipXmax;
clipCorners[1].y = viewData.clipYmin;
clipCorners[1].z = viewData.clipZmin;
clipCorners[2].x = viewData.clipXmax;
clipCorners[2].y = viewData.clipYmin;
clipCorners[2].z = viewData.clipZmax;
clipCorners[3].x = viewData.clipXmin;
clipCorners[3].y = viewData.clipYmin;
clipCorners[3].z = viewData.clipZmax;
clipCorners[4].x = viewData.clipXmin;
clipCorners[4].y = viewData.clipYmax;
clipCorners[4].z = viewData.clipZmin;
clipCorners[5].x = viewData.clipXmax;
clipCorners[5].y = viewData.clipYmax;
clipCorners[5].z = viewData.clipZmin;
clipCorners[6].x = viewData.clipXmax;
clipCorners[6].y = viewData.clipYmax;
clipCorners[6].z = viewData.clipZmax;
clipCorners[7].x = viewData.clipXmin;
clipCorners[7].y = viewData.clipYmax;
clipCorners[7].z = viewData.clipZmax;
GSetLineAttributes(trashGC,0,LineSolid,CapButt,JoinMiter,dFlag);
/* project the 8 corners of the box */
for (i=0;i<8;i++) projectAPoint(&(clipCorners[i]));
for (i=0;i<6;i++) {
clipBox[i].inside = ((clipBox[i].pointsPtr[2]->px -
clipBox[i].pointsPtr[1]->px) *
(clipBox[i].pointsPtr[1]->py -
clipBox[i].pointsPtr[0]->py) -
(clipBox[i].pointsPtr[2]->py -
clipBox[i].pointsPtr[1]->py) *
(clipBox[i].pointsPtr[1]->px -
clipBox[i].pointsPtr[0]->px)) < 0;
if (clipBox[i].inside) {
for (j=0; j<3; j++) {
quadMesh[j].x = clipBox[i].pointsPtr[j]->px;
quadMesh[j].y = clipBox[i].pointsPtr[j]->py;
}
if (viewport->monoOn || mono) {
GSetForeground(trashGC,(float)foregroundColor,dFlag);
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
} else {
if (dFlag == PSoption) {
GSetForeground(trashGC,(float)clipBoxInline, dFlag);
line[0].x = quadMesh[0].x; line[0].y = quadMesh[0].y;
line[1].x = quadMesh[1].x; line[1].y = quadMesh[1].y;
PSDrawColor(clipbox_rgb.r,clipbox_rgb.g,clipbox_rgb.b,line,2);
line[0].x = quadMesh[1].x; line[0].y = quadMesh[1].y;
line[1].x = quadMesh[2].x; line[1].y = quadMesh[2].y;
PSDrawColor(clipbox_rgb.r,clipbox_rgb.g,clipbox_rgb.b,line,2);
} else {
GSetForeground(trashGC,(float)clipBoxInline, dFlag);
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
}
}
}
}
} /* if viewData.clipbox */
/* VOLUME panel stuff */
if ((doingPanel == VOLUMEpanel) || viewData.box) {
GSetLineAttributes(trashGC,0,LineSolid,CapButt,JoinMiter,dFlag);
for (i=0;i<8;i++) {
/* project the 8 corners of the box */
projectAPoint(&(corners[i]));
if (i) {
if (corners[i].pz > pzMax) pzMax = corners[i].pz;
else if (corners[i].pz < pzMin) pzMin = corners[i].pz;
} else
pzMax = pzMin = corners[i].pz;
}
for (i=0;i<6;i++) {
/* Process the 6 sides of the boxes.
Here, we calculate, for each side (defined by two segments)
whether it is facing towards or away from the viewer. if
facing, away, we draw them first. later we draw the ones
facing the viewer. (this is a sort of backface removal
scheme. */
/* We define the normal vector for the box as vA X vB where
vA=p2-p0 and vB=p1-p0. All we really care about, though,
is what sign the normal is (whether it is towards or away
from the viewer - so we just take the triple product of
it against the eye vector, which is, conveniently enough,
simply [0 0 1]. Hence, only the Z component of the
cross product is calculated. (Actually, we are using the
projected normal - that's how we are able to use the
trick of just taking the Z component. */
box[i].inside = ((box[i].pointsPtr[2]->px -
box[i].pointsPtr[0]->px) * /* Ax * */
(box[i].pointsPtr[1]->py -
box[i].pointsPtr[0]->py) - /* By - */
(box[i].pointsPtr[2]->py -
box[i].pointsPtr[0]->py) * /* Ay * */
(box[i].pointsPtr[1]->px -
box[i].pointsPtr[0]->px)) /* Bx */
< 0;
if (box[i].inside) {
for (j=0; j<3; j++) {
quadMesh[j].x = box[i].pointsPtr[j]->px;
quadMesh[j].y = box[i].pointsPtr[j]->py;
}
if (viewport->monoOn || mono) {
GSetForeground(trashGC,(float)foregroundColor,dFlag);
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
} else {
if (dFlag == PSoption) {
GSetForeground(trashGC,(float)boxInline, dFlag );
line[0].x = quadMesh[0].x; line[0].y = quadMesh[0].y;
line[1].x = quadMesh[1].x; line[1].y = quadMesh[1].y;
PSDrawColor(boundbox_rgb.r,boundbox_rgb.g,boundbox_rgb.b,line,2);
line[0].x = quadMesh[1].x; line[0].y = quadMesh[1].y;
line[1].x = quadMesh[2].x; line[1].y = quadMesh[2].y;
PSDrawColor(boundbox_rgb.r,boundbox_rgb.g,boundbox_rgb.b,line,2);
} else {
GSetForeground(trashGC,(float)boxInline, dFlag );
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
}
}
}
}
} /* if viewData.box */
/* Write out view data */
if (dFlag == Xoption) { /* do this only for X option */
writeControlMessage();
XFlush(dsply);
}
}
/********************************/
/*** void drawTheViewport() ***/
/********************************/
void
#ifdef _NO_PROTO
drawTheViewport (dFlag)
int dFlag; /* display flag: PS, X,... */
#else
drawTheViewport (int dFlag)
#endif
{
int i,j;
XPoint line[2];
RGB clipbox_rgb, boundbox_rgb;
clipbox_rgb.r = 0.4; clipbox_rgb.g = 0.5; clipbox_rgb.b = 0.9;
boundbox_rgb.r = 0.4; boundbox_rgb.g = 0.7; boundbox_rgb.b = 0.9;
/**** Draw Routine ****/
if (viewport->allowDraw && (doingPanel != VOLUMEpanel)) {
/* Do not draw the mesh stuff if we're in the process of changing
the viewing volume; we just want to see the volume */
/* drawMore allows the drawing to continue if no relevant XEvent occurs */
drawMore = yes;
drawMore = keepDrawingViewport();
draw3DComponents(dFlag);
} /*if viewport->allowDraw */
/**** Post Draw Routine ****/
if (viewData.clipbox) { /* draw the front 3 lines of region box */
GSetLineAttributes(trashGC,0,LineSolid,CapButt,JoinMiter,dFlag);
for (i=0; i<6; i++) {
if (!(clipBox[i].inside)) {
for (j=0; j<4; j++) {
quadMesh[j].x = clipBox[i].pointsPtr[j]->px;
quadMesh[j].y = clipBox[i].pointsPtr[j]->py;
}
if (viewport->monoOn || mono) {
GSetForeground(trashGC,(float)foregroundColor,dFlag);
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
} else {
if (dFlag == PSoption) {
GSetForeground(trashGC,(float)boxInline, dFlag );
line[0].x = quadMesh[0].x; line[0].y = quadMesh[0].y;
line[1].x = quadMesh[1].x; line[1].y = quadMesh[1].y;
PSDrawColor(clipbox_rgb.r,clipbox_rgb.g,clipbox_rgb.b,line,2);
line[0].x = quadMesh[1].x; line[0].y = quadMesh[1].y;
line[1].x = quadMesh[2].x; line[1].y = quadMesh[2].y;
PSDrawColor(clipbox_rgb.r,clipbox_rgb.g,clipbox_rgb.b,line,2);
} else {
GSetForeground(trashGC,(float)boxInline, dFlag );
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
}
}
}
}
}
if ((doingPanel==VOLUMEpanel) || viewData.box) {
GSetLineAttributes(trashGC,0,LineSolid,CapButt,JoinMiter,dFlag);
for (i=0; i<6; i++) {
if (!(box[i].inside)) {
for (j=0; j<4; j++) {
quadMesh[j].x = box[i].pointsPtr[j]->px;
quadMesh[j].y = box[i].pointsPtr[j]->py;
}
if (viewport->monoOn || mono) {
GSetForeground(trashGC,(float)foregroundColor,dFlag);
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
} else {
if (dFlag == PSoption) {
GSetForeground(trashGC,(float)boxInline, dFlag );
line[0].x = quadMesh[0].x; line[0].y = quadMesh[0].y;
line[1].x = quadMesh[1].x; line[1].y = quadMesh[1].y;
PSDrawColor(boundbox_rgb.r,boundbox_rgb.g,boundbox_rgb.b,line,2);
line[0].x = quadMesh[1].x; line[0].y = quadMesh[1].y;
line[1].x = quadMesh[2].x; line[1].y = quadMesh[2].y;
PSDrawColor(boundbox_rgb.r,boundbox_rgb.g,boundbox_rgb.b,line,2);
} else {
GSetForeground(trashGC,(float)boxInline, dFlag );
GDrawLines(trashGC, viewport->viewWindow, quadMesh, 3,
CoordModeOrigin, dFlag);
}
}
}
}
}
if (dFlag == Xoption) /* do this for X option only */
XFlush(dsply);
if (smoothError) {
strcpy(control->message,"Cannot alloc more smooth shades.");
writeControlMessage();
smoothError = no;
}
} /* drawTheViewport */
/************************************
*** viewPoints *makeViewport() ***
************************************/
viewPoints *
#ifdef _NO_PROTO
makeViewport ()
#else
makeViewport (void)
#endif
{
Pixmap spadbits,spadmask;
XSetWindowAttributes viewAttrib;
XSizeHints titleSizeHints;
Window viewTitleWindow, viewGraphWindow;
XColor foreColor, backColor;
/**** create a viewport ****/
if (!(viewport = (viewPoints *)saymem("viewport3D.c",
1,sizeof(viewPoints)))) {
fprintf(stderr,"Ran out of memory trying to create a viewport.\n");
exitWithAck(RootWindow(dsply,scrn),Window,-1);
}
/* Definition of the 4x4 identity matrix. */
I[0][0] = 1.0; I[0][1] = 0.0; I[0][2] = 0.0; I[0][3] = 0.0;
I[1][0] = 0.0; I[1][1] = 1.0; I[1][2] = 0.0; I[1][3] = 0.0;
I[2][0] = 0.0; I[2][1] = 0.0; I[2][2] = 1.0; I[2][3] = 0.0;
I[3][0] = 0.0; I[3][1] = 0.0; I[3][2] = 0.0; I[3][3] = 1.0;
viewport->viewportKey = viewportKeyNum++;
viewport->nextViewport = 0;
viewport->prevViewport = 0;
viewport->deltaX = viewport->deltaX0 = viewData.deltaX;
viewport->deltaY = viewport->deltaY0 = viewData.deltaY;
viewport->deltaZ = viewport->deltaZ0 = viewData.deltaZ;
viewport->scale = viewport->scale0 = viewData.scale;
viewport->scaleX = viewData.scaleX;
viewport->scaleY = viewData.scaleY;
viewport->scaleZ = viewData.scaleZ;
viewport->transX = (viewData.xmax + viewData.xmin)/2.0;
viewport->transY = (viewData.ymax + viewData.ymin)/2.0;
viewport->transZ = (viewData.zmax + viewData.zmin)/2.0;
viewport->theta = viewport->axestheta = viewport->theta0 = viewData.theta;
viewport->phi = viewport->axesphi = viewport->phi0 = viewData.phi;
viewport->thetaObj = 0.0;
viewport->phiObj = 0.0;
strcpy(viewport->title,viewData.title);
viewport->axesOn = yes;
viewport->regionOn = no;
viewport->monoOn = no;
viewport->zoomXOn = yes;
viewport->zoomYOn = yes;
viewport->zoomZOn = yes;
viewport->originrOn = yes;
viewport->objectrOn = no;
viewport->originFlag = no;
viewport->xyOn = no;
viewport->xzOn = no;
viewport->yzOn = no;
viewport->closing = no;
viewport->allowDraw = yes; /*if no, just draw axes the first time */
viewport->needNorm = yes;
viewport->lightVector[0] = -0.5;
viewport->lightVector[1] = 0.5;
viewport->lightVector[2] = 0.5;
viewport->translucency = viewData.translucency;
viewport->hueOffset = viewData.hueOff;
viewport->numberOfHues = viewData.numOfHues;
viewport->hueTop = viewData.hueOff + viewData.numOfHues;
if (viewport->hueTop > totalHues-1) viewport->hueTop = totalHues-1;
viewport->diagonals = viewData.diagonals;
/* make theta in [0..2pi) and phi in (-pi..pi] */
while (viewport->theta >= two_pi) {
viewport->theta -= two_pi;
}
while (viewport->theta < 0.0) {
viewport->theta += two_pi;
}
while (viewport->phi > pi) {
viewport->phi -= two_pi;
}
while (viewport->phi <= -pi) {
viewport->phi += two_pi;
}
while (viewport->axestheta >= two_pi) {
viewport->axestheta -= two_pi;
}
while (viewport->axestheta < 0.0) {
viewport->axestheta += two_pi;
}
while (viewport->axesphi > pi) {
viewport->axesphi -= two_pi;
}
while (viewport->axesphi <= -pi) {
viewport->axesphi += two_pi;
}
/* Initialize the rotation matrix about the origin. */
sinTheta = sin(-viewport->theta);
cosTheta = cos(-viewport->theta);
sinPhi = sin(viewport->phi);
cosPhi = cos(viewport->phi);
ROTATE(R); /* angles theta and phi are global */
/* Initialize the rotation matrix about the object's center of volume. */
sinTheta = sin(-viewport->thetaObj);
cosTheta = cos(-viewport->thetaObj);
sinPhi = sin(viewport->phiObj);
cosPhi = cos(viewport->phiObj);
ROTATE1(R1); /* angles theta and phi are global */
/* Initialize the non-uniform scaling matrix. */
SCALE(viewport->scaleX,viewport->scaleY,viewport->scaleZ,S);
/* Initialize the translation matrix. */
TRANSLATE(-viewport->deltaX,-viewport->deltaY,0.0,T);
/**** make the windows for the viewport ****/
spadbits = XCreateBitmapFromData(dsply,rtWindow,
spadBitmap_bits,
spadBitmap_width,spadBitmap_height);
spadmask = XCreateBitmapFromData(dsply,rtWindow,
spadMask_bits,
spadMask_width,spadMask_height);
viewAttrib.background_pixel = backgroundColor;
viewAttrib.border_pixel = foregroundColor;
viewAttrib.override_redirect = overrideManager;
viewAttrib.colormap = colorMap;
foreColor.pixel = foregroundColor;
backColor.pixel = backgroundColor;
/*
foreColor.pixel = viewCursorForeground;
backColor.pixel = viewCursorBackground;
*/
XQueryColor(dsply,colorMap,&foreColor);
XQueryColor(dsply,colorMap,&backColor);
viewAttrib.cursor = XCreatePixmapCursor(dsply,spadbits,spadmask,
&foreColor,&backColor,spadBitmap_x_hot,spadBitmap_y_hot);
viewAttrib.event_mask = titleMASK;
if (viewData.vW) {
titleSizeHints.flags = PPosition | PSize;
titleSizeHints.x = viewData.vX;
titleSizeHints.y = viewData.vY;
titleSizeHints.width = viewData.vW;
titleSizeHints.height = viewData.vH;
} else { /* ain't gonna allow this for now... */
titleSizeHints.flags = PSize;
titleSizeHints.width = viewWidth;
titleSizeHints.height = viewHeight;
}
viewTitleWindow = XCreateWindow(dsply /* display */,
rtWindow, /* parent */
viewData.vX, /* x */
viewData.vY, /* y */
viewData.vW, /* width */
viewData.vH, /* height */
/* viewBorderWidth+3*/ 0, /* border width */
CopyFromParent, /* depth */
InputOutput, /* class */
CopyFromParent, /* visual */
viewportTitleCreateMASK,/* valuemask */
&viewAttrib /* attributes */);
wm_delete_window = XInternAtom(dsply, "WM_DELETE_WINDOW", False);
(void) XSetWMProtocols(dsply, viewTitleWindow, &wm_delete_window, 1);
XSetNormalHints(dsply,viewTitleWindow,&titleSizeHints);
if (strlen(viewport->title) < 30)
XSetStandardProperties(dsply,viewTitleWindow,"AXIOM 3D",viewport->title,
None,NULL,0,&titleSizeHints);
else
XSetStandardProperties(dsply,viewTitleWindow,"AXIOM 3D","3D AXIOM Graph",
None,NULL,0,&titleSizeHints);
viewport->titleWindow = viewTitleWindow;
viewAttrib.event_mask = viewportMASK;
viewSizeHints.flags = PPosition | PSize;
viewSizeHints.x = -(viewBorderWidth+3);
viewSizeHints.x = 0; /* lose this */
viewSizeHints.y = titleHeight;
viewSizeHints.width = titleSizeHints.width;
viewSizeHints.height = titleSizeHints.height-(titleHeight+appendixHeight);
viewGraphWindow = XCreateWindow(dsply, /* display */
viewTitleWindow, /* parent */
viewSizeHints.x, /* x */
viewSizeHints.y, /* y */
viewSizeHints.width, /* width */
viewSizeHints.height, /* height */
/* viewBorderWidth+3*/0, /* border width */
CopyFromParent, /* depth */
InputOutput, /* class */
CopyFromParent, /* visual */
viewportCreateMASK, /* valuemask */
&viewAttrib /* attributes */);
XSetNormalHints(dsply,viewGraphWindow,&viewSizeHints);
XSetStandardProperties(dsply,viewGraphWindow,"","",None,NULL,0,
&viewSizeHints);
viewport->viewWindow = viewGraphWindow;
graphWindowAttrib.width = viewSizeHints.width;
graphWindowAttrib.height = viewSizeHints.height;
if (viewport->hueOffset != viewport->hueTop) {
multiColorFlag = yes;
redoColor = no;
} else {
if (viewport->hueTop < 11)
smoothHue = viewport->hueTop*6;
else {
if (viewport->hueTop > 10 && viewport->hueTop < 16)
smoothHue = viewport->hueTop*20 - 140;
else smoothHue = viewport->hueTop*12 - 12;
}
redoColor = yes;
}
/**** Make the control panel for the viewport. ****/
XSync(dsply,0);
control = viewport->controlPanel = makeControlPanel();
makeLightingPanel();
makeVolumePanel();
makeSavePanel();
makeQuitPanel();
if ((viewport->haveControl = viewData.showCP))
putControlPanelSomewhere(anywhere);
firstTime = yes;
return(viewport);
} /* makeViewport() */
/*****************************
* void postMakeViewport() *
* *
* post processing when *
* creating a viewport. *
* 1) assign min,max values *
* for the box volume *
*****************************/
void
#ifdef _NO_PROTO
postMakeViewport ()
#else
postMakeViewport (void)
#endif
{
corners[0].x = viewData.xmin; corners[0].y = viewData.ymin;
corners[0].z = viewData.zmin;
corners[1].x = viewData.xmax; corners[1].y = viewData.ymin;
corners[1].z = viewData.zmin;
corners[2].x = viewData.xmax; corners[2].y = viewData.ymin;
corners[2].z = viewData.zmax;
corners[3].x = viewData.xmin; corners[3].y = viewData.ymin;
corners[3].z = viewData.zmax;
corners[4].x = viewData.xmin; corners[4].y = viewData.ymax;
corners[4].z = viewData.zmin;
corners[5].x = viewData.xmax; corners[5].y = viewData.ymax;
corners[5].z = viewData.zmin;
corners[6].x = viewData.xmax; corners[6].y = viewData.ymax;
corners[6].z = viewData.zmax;
corners[7].x = viewData.xmin; corners[7].y = viewData.ymax;
corners[7].z = viewData.zmax;
box[2].pointsPtr[0] = &(corners[0]);
box[2].pointsPtr[1] = &(corners[1]);
box[2].pointsPtr[2] = &(corners[2]);
box[2].pointsPtr[3] = &(corners[3]);
box[3].pointsPtr[0] = &(corners[1]);
box[3].pointsPtr[1] = &(corners[5]);
box[3].pointsPtr[2] = &(corners[6]);
box[3].pointsPtr[3] = &(corners[2]);
box[0].pointsPtr[0] = &(corners[4]);
box[0].pointsPtr[1] = &(corners[7]);
box[0].pointsPtr[2] = &(corners[6]);
box[0].pointsPtr[3] = &(corners[5]);
box[1].pointsPtr[0] = &(corners[0]);
box[1].pointsPtr[1] = &(corners[3]);
box[1].pointsPtr[2] = &(corners[7]);
box[1].pointsPtr[3] = &(corners[4]);
box[5].pointsPtr[0] = &(corners[3]);
box[5].pointsPtr[1] = &(corners[2]);
box[5].pointsPtr[2] = &(corners[6]);
box[5].pointsPtr[3] = &(corners[7]);
box[4].pointsPtr[0] = &(corners[0]);
box[4].pointsPtr[1] = &(corners[4]);
box[4].pointsPtr[2] = &(corners[5]);
box[4].pointsPtr[3] = &(corners[1]);
/* clip box */
clipBox[0].pointsPtr[0] = &(clipCorners[0]);
clipBox[0].pointsPtr[1] = &(clipCorners[1]);
clipBox[0].pointsPtr[2] = &(clipCorners[2]);
clipBox[0].pointsPtr[3] = &(clipCorners[3]);
clipBox[1].pointsPtr[0] = &(clipCorners[1]);
clipBox[1].pointsPtr[1] = &(clipCorners[5]);
clipBox[1].pointsPtr[2] = &(clipCorners[6]);
clipBox[1].pointsPtr[3] = &(clipCorners[2]);
clipBox[2].pointsPtr[0] = &(clipCorners[4]);
clipBox[2].pointsPtr[1] = &(clipCorners[7]);
clipBox[2].pointsPtr[2] = &(clipCorners[6]);
clipBox[2].pointsPtr[3] = &(clipCorners[5]);
clipBox[3].pointsPtr[0] = &(clipCorners[0]);
clipBox[3].pointsPtr[1] = &(clipCorners[3]);
clipBox[3].pointsPtr[2] = &(clipCorners[7]);
clipBox[3].pointsPtr[3] = &(clipCorners[4]);
clipBox[4].pointsPtr[0] = &(clipCorners[3]);
clipBox[4].pointsPtr[1] = &(clipCorners[2]);
clipBox[4].pointsPtr[2] = &(clipCorners[6]);
clipBox[4].pointsPtr[3] = &(clipCorners[7]);
clipBox[5].pointsPtr[0] = &(clipCorners[0]);
clipBox[5].pointsPtr[1] = &(clipCorners[4]);
clipBox[5].pointsPtr[2] = &(clipCorners[5]);
clipBox[5].pointsPtr[3] = &(clipCorners[1]);
}
/*****************************************
*** int keepDrawingViewport() ***
*****************************************/
int
#ifdef _NO_PROTO
keepDrawingViewport()
#else
keepDrawingViewport(void)
#endif
{
XEvent peekEvent;
int retVal;
if (XPending(dsply)) {
XPeekEvent(dsply,&peekEvent);
if (((peekEvent.type == Expose) &&
((peekEvent.xany).window == viewport->viewWindow)) ||
((peekEvent.type == Expose) &&
((peekEvent.xany).window == viewport->titleWindow)) ||
((peekEvent.type == Expose) &&
((peekEvent.xany).window == control->controlWindow))) {
retVal = firstTime;
} else if ((peekEvent.xbutton.type == ButtonRelease) ||
((peekEvent.type == LeaveNotify) && !(followMouse)) ||
((peekEvent.type == MotionNotify) && !(followMouse)) ||
(peekEvent.type == ResizeRequest)) {
XNextEvent(dsply,&peekEvent);
followMouse = no;
retVal = yes;
} else if ((peekEvent.xany).window == (control->buttonQueue[hideControl]).self) {
viewport->haveControl = no;
XUnmapWindow(dsply,control->controlWindow);
retVal = yes;
} else {
retVal = no;
}
} else {
retVal = !followMouse;
}
if (writeImage) retVal = yes;
drawMore = no;
return(retVal);
}
|