forked from gnuplot/gnuplot-old
/
graph3d.c
1964 lines (1705 loc) · 55.9 KB
/
graph3d.c
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
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef lint
static char *RCSid = "$Id: graph3d.c,v 1.9 1998/10/05 12:40:09 lhecking Exp $";
#endif
/* GNUPLOT - graph3d.c */
/*[
* Copyright 1986 - 1993, 1998 Thomas Williams, Colin Kelley
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the complete modified source code. Modifications are to
* be distributed as patches to the released version. Permission to
* distribute binaries produced by compiling modified sources is granted,
* provided you
* 1. distribute the corresponding source modifications from the
* released version in the form of a patch file along with the binaries,
* 2. add special version identification to distinguish your version
* in addition to the base release version number,
* 3. provide your name and address as the primary contact for the
* support of your modified version, and
* 4. retain our contact information in regard to use of the base
* software.
* Permission to distribute the released version of the source code along
* with corresponding source modifications in the form of a patch file is
* granted with same provisions 2 through 4 for binary distributions.
*
* This software is provided "as is" without express or implied warranty
* to the extent permitted by applicable law.
]*/
/*
* AUTHORS
*
* Original Software:
* Gershon Elber and many others.
*
* 19 September 1992 Lawrence Crowl (crowl@cs.orst.edu)
* Added user-specified bases for log scaling.
*
* 3.6 - split graph3d.c into graph3d.c (graph),
* util3d.c (intersections, etc)
* hidden3d.c (hidden-line removal code)
*
*/
#include "plot.h"
#include "setshow.h"
static int p_height;
static int p_width; /* pointsize * t->h_tic */
static int key_entry_height; /* bigger of t->v_size, pointsize*t->v_tick */
int suppressMove = 0; /* for preventing moveto while drawing contours */
/*
* hidden_line_type_above, hidden_line_type_below - controls type of lines
* for above and below parts of the surface.
* hidden_no_update - if TRUE lines will be hidden line removed but they
* are not assumed to be part of the surface (i.e. grid) and therefore
* do not influence the hidings.
* hidden_active - TRUE if hidden lines are to be removed.
*/
int hidden_active = FALSE;
int hidden_no_update; /* HBB 980324: made this visible despite LITE */
/* LITE defines a restricted memory version for MS-DOS, which doesn't
* use the routines in hidden3d.c
*/
#ifndef LITE
int hidden_line_type_above, hidden_line_type_below;
#endif /* LITE */
static double LogScale __PROTO((double coord, TBOOLEAN is_log, double log_base_log,
char *what, char *axis));
static void plot3d_impulses __PROTO((struct surface_points *plot));
static void plot3d_lines __PROTO((struct surface_points *plot));
static void plot3d_points __PROTO((struct surface_points *plot));
static void plot3d_dots __PROTO((struct surface_points *plot));
static void cntr3d_impulses __PROTO((struct gnuplot_contours *cntr, struct surface_points *plot));
static void cntr3d_lines __PROTO((struct gnuplot_contours *cntr));
static void cntr3d_points __PROTO((struct gnuplot_contours *cntr, struct surface_points *plot));
static void cntr3d_dots __PROTO((struct gnuplot_contours *cntr));
static void check_corner_height __PROTO((struct coordinate GPHUGE *point, double height[2][2], double depth[2][2]));
static void draw_bottom_grid __PROTO((struct surface_points *plot, int plot_count));
static void xtick_callback __PROTO((int axis, double place, char *text, struct lp_style_type grid));
static void ytick_callback __PROTO((int axis, double place, char *text, struct lp_style_type grid));
static void ztick_callback __PROTO((int axis, double place, char *text, struct lp_style_type grid));
static void setlinestyle __PROTO((struct lp_style_type style));
static void boundary3d __PROTO((int scaling, struct surface_points *plots, int count));
#if 0 /* not used */
static double dbl_raise __PROTO((double x, int y));
#endif
static void map_position __PROTO((struct position *pos, unsigned int *x, unsigned int *y, char *what));
/* put entries in the key */
static void key_sample_line __PROTO((int xl, int yl));
static void key_sample_point __PROTO((int xl, int yl, int pointtype));
static void key_text __PROTO((int xl, int yl, char *text));
#if defined(sun386) || defined(AMIGA_SC_6_1)
static double CheckLog __PROTO((TBOOLEAN is_log, double base_log, double x));
#endif
/*
* The Amiga SAS/C 6.2 compiler moans about macro envocations causing
* multiple calls to functions. I converted these macros to inline
* functions coping with the problem without loosing speed.
* (MGR, 1993)
*/
#ifdef AMIGA_SC_6_1
GP_INLINE static TBOOLEAN i_inrange(int z,int min,int max)
{
return((min<max) ? ((z >= min) && (z <= max)) : ((z >= max) && (z <= min)));
}
GP_INLINE static double f_max(double a,double b)
{
return(max(a,b));
}
GP_INLINE static double f_min(double a,double b)
{
return(min(a,b));
}
#else
#define f_max(a,b) GPMAX((a),(b))
#define f_min(a,b) GPMIN((a),(b))
#define i_inrange(z,a,b) inrange((z),(a),(b))
#endif
#define apx_eq(x,y) (fabs(x-y) < 0.001)
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define SQR(x) ((x) * (x))
/* Define the boundary of the plot
* These are computed at each call to do_plot, and are constant over
* the period of one do_plot. They actually only change when the term
* type changes and when the 'set size' factors change.
*/
/* in order to allow graphic.c to use clip_draw_line, we must
* share xleft, xright, ybot, ytop with graphics.c
*/
extern int xleft, xright, ybot, ytop;
int xmiddle, ymiddle, xscaler, yscaler;
static int ptitl_cnt;
static int max_ptitl_len;
static int titlelin;
static int key_sample_width, key_rows, key_cols, key_col_wth, yl_ref;
static int ktitle_lines = 0;
/* Boundary and scale factors, in user coordinates */
/* x_min3d, x_max3d, y_min3d, y_max3d, z_min3d, z_max3d are local to this
* file and are not the same as variables of the same names in other files
*/
/*static double x_min3d, x_max3d, y_min3d, y_max3d, z_min3d, z_max3d;*/
/* sizes are now set in min_array[], max_array[] from command.c */
extern double min_array[], max_array[];
extern int auto_array[], log_array[];
extern double base_array[], log_base_array[];
/* for convenience while converting to use these arrays */
#define x_min3d min_array[FIRST_X_AXIS]
#define x_max3d max_array[FIRST_X_AXIS]
#define y_min3d min_array[FIRST_Y_AXIS]
#define y_max3d max_array[FIRST_Y_AXIS]
#define z_min3d min_array[FIRST_Z_AXIS]
#define z_max3d max_array[FIRST_Z_AXIS]
/* There are several z's to take into account - I hope I get these
* right !
*
* ceiling_z is the highest z in use
* floor_z is the lowest z in use
* base_z is the z of the base
* min3d_z is the lowest z of the graph area
* max3d_z is the highest z of the graph area
*
* ceiling_z is either max3d_z or base_z, and similarly for floor_z
* There should be no part of graph drawn outside
* min3d_z:max3d_z - apart from arrows, perhaps
*/
double ceiling_z, floor_z, base_z;
/* and some bodges while making the change */
#define min3d_z min_array[FIRST_Z_AXIS]
#define max3d_z max_array[FIRST_Z_AXIS]
double xscale3d, yscale3d, zscale3d;
typedef double transform_matrix[4][4];
transform_matrix trans_mat;
static double xaxis_y, yaxis_x, zaxis_x, zaxis_y;
/* the co-ordinates of the back corner */
static double back_x, back_y;
/* the penalty for convenience of using tic_gen to make callbacks
* to tick routines is that we cant pass parameters very easily.
* We communicate with the tick_callbacks using static variables
*/
/* unit vector (terminal coords) */
static double tic_unitx, tic_unity;
/* (DFK) Watch for cancellation error near zero on axes labels */
#define SIGNIF (0.01) /* less than one hundredth of a tic mark */
#define CheckZero(x,tic) (fabs(x) < ((tic) * SIGNIF) ? 0.0 : (x))
#define NearlyEqual(x,y,tic) (fabs((x)-(y)) < ((tic) * SIGNIF))
/* And the functions to map from user to terminal coordinates */
#define map_x(x) (int)(x+0.5) /* maps floating point x to screen */
#define map_y(y) (int)(y+0.5) /* same for y */
/* And the functions to map from user 3D space into normalized -1..1 */
#define map_x3d(x) ((x-x_min3d)*xscale3d-1.0)
#define map_y3d(y) ((y-y_min3d)*yscale3d-1.0)
#define map_z3d(z) ((z-floor_z)*zscale3d-1.0)
/* Initialize the line style using the current device and set hidden styles */
/* to it as well if hidden line removal is enabled. */
static void setlinestyle(style)
struct lp_style_type style;
{
register struct termentry *t = term;
term_apply_lp_properties(&style);
#ifndef LITE
if (hidden3d) {
hidden_line_type_above = style.l_type;
hidden_line_type_below = style.l_type;
}
#endif /* LITE */
}
#ifndef LITE
#endif /* not LITE */
/* (DFK) For some reason, the Sun386i compiler screws up with the CheckLog
* macro, so I write it as a function on that machine.
*
* Amiga SAS/C 6.2 thinks it will do too much work calling functions in
* macro arguments twice, thus I inline theese functions. (MGR, 1993)
*/
#if defined(sun386) || defined(AMIGA_SC_6_1)
GP_INLINE static double
CheckLog(is_log, base_log, x)
TBOOLEAN is_log;
double base_log;
double x;
{
if (is_log)
return(pow(base_log, x));
else
return(x);
}
#else
/* (DFK) Use 10^x if logscale is in effect, else x */
#define CheckLog(is_log, base_log, x) ((is_log) ? pow(base_log, (x)) : (x))
#endif /* sun386 || SAS/C */
static double
LogScale(coord, is_log, log_base_log, what, axis)
double coord; /* the value */
TBOOLEAN is_log; /* is this axis in logscale? */
double log_base_log; /* if so, the log of its base */
char *what; /* what is the coord for? */
char *axis; /* which axis is this for ("x" or "y")? */
{
if (is_log) {
if (coord <= 0.0) {
char errbuf[100]; /* place to write error message */
(void) sprintf(errbuf,"%s has %s coord of %g; must be above 0 for log scale!",
what, axis, coord);
graph_error(errbuf);
} else
return(log(coord)/log_base_log);
}
return(coord);
}
/* And the functions to map from user 3D space to terminal coordinates */
void map3d_xy(x, y, z, xt, yt)
double x, y, z;
unsigned int *xt, *yt;
{
int i,j;
double v[4], res[4], /* Homogeneous coords. vectors. */
w = trans_mat[3][3];
v[0] = map_x3d(x); /* Normalize object space to -1..1 */
v[1] = map_y3d(y);
v[2] = map_z3d(z);
v[3] = 1.0;
for (i = 0; i < 2; i++) { /* Dont use the third axes (z). */
res[i] = trans_mat[3][i]; /* Initiate it with the weight factor. */
for (j = 0; j < 3; j++) res[i] += v[j] * trans_mat[j][i];
}
for (i = 0; i < 3; i++) w += v[i] * trans_mat[i][3];
if (w == 0) w = 1e-5;
*xt = (unsigned int) ((res[0] * xscaler / w) + xmiddle);
*yt = (unsigned int) ((res[1] * yscaler / w) + ymiddle);
}
/* And the functions to map from user 3D space to terminal z coordinate */
int map3d_z(x, y, z)
double x, y, z;
{
int i, zt;
double v[4], res, /* Homogeneous coords. vectors. */
w = trans_mat[3][3];
v[0] = map_x3d(x); /* Normalize object space to -1..1 */
v[1] = map_y3d(y);
v[2] = map_z3d(z);
v[3] = 1.0;
res = trans_mat[3][2]; /* Initiate it with the weight factor. */
for (i = 0; i < 3; i++) res += v[i] * trans_mat[i][2];
if(w == 0) w= 1e-5;
for (i = 0; i < 3; i++) w += v[i] * trans_mat[i][3];
zt = ((int) (res * 16384 / w));
return zt;
}
/* borders of plotting area */
/* computed once on every call to do_plot */
static void boundary3d(scaling,plots,count)
TBOOLEAN scaling; /* TRUE if terminal is doing the scaling */
struct surface_points *plots;
int count;
{
register struct termentry *t = term;
int ytlen, i;
titlelin = 0;
p_height = pointsize * t->v_tic;
p_width = pointsize * t->h_tic;
if (key_swidth >= 0)
key_sample_width = key_swidth*(t->h_char) + pointsize*(t->h_tic);
else
key_sample_width = 0;
key_entry_height = pointsize * (t->v_tic) * 1.25 * key_vert_factor;
if (key_entry_height < (t->v_char) )
key_entry_height = (t->v_char)*key_vert_factor; /* is this reasonable ? */
/* count max_len key and number keys (plot-titles and contour labels) with len > 0 */
max_ptitl_len = find_maxl_keys3d(plots,count,&ptitl_cnt);
if ( (ytlen = label_width(key_title,&ktitle_lines)) > max_ptitl_len )
max_ptitl_len = ytlen;
key_col_wth = (max_ptitl_len + 4 ) * (t->h_char) + key_sample_width;
/* luecken@udel.edu modifications
sizes the plot to take up more of available resolution */
if ( lmargin >= 0 )
xleft = (t->h_char)*lmargin;
else
xleft = (t->h_char)*2 + (t->h_tic);
xright = (scaling ? 1 : xsize) * (t->xmax) - (t->h_char)*2 - (t->h_tic);
key_rows = ptitl_cnt;
key_cols = 1;
if (key == -1 && key_vpos == TUNDER ) {
/* calculate max no cols, limited by label-length */
key_cols = (int)(xright - xleft)/((max_ptitl_len + 4 ) * (t->h_char) + key_sample_width);
key_rows = (int)(ptitl_cnt/key_cols)+((ptitl_cnt%key_cols)>0);
/* now calculate actual no cols depending on no rows */
key_cols = (int)(ptitl_cnt/key_rows)+((ptitl_cnt%key_rows)>0);
key_col_wth = (int)(xright - xleft)/key_cols;
/* key_rows += ktitle_lines; - messes up key - div */
}
/* this should also consider the view and number of lines in xformat || yformat || xlabel || ylabel */
ybot = (t->v_char)*2.5 + 1; /* an absolute 1, with no terminal-dependent scaling ? */
if (key_rows&&key_vpos == TUNDER)
ybot += key_rows*key_entry_height + ktitle_lines*t->v_char;
if (strlen(title.text)) {
titlelin++;
for(i = 0;i<strlen(title.text);i++) {
if (title.text[i] == '\\') titlelin++;
}
}
ytop = (scaling ? 1 : ysize) * (t->ymax) - (t->v_char)*(titlelin+1.5) - 1;
if (key == -1 && key_vpos != TUNDER ) {
/* calculate max no rows, limited be ytop-ybot */
i = (int)(ytop-ybot)/(t->v_char) - 1 - ktitle_lines;
if (ptitl_cnt > i) {
key_cols = (int)(ptitl_cnt/i)+((ptitl_cnt%i)>0);
/* now calculate actual no rows depending on no cols */
key_rows = (int)(ptitl_cnt/key_cols)+((ptitl_cnt%key_cols)>0);
}
key_rows += ktitle_lines;
}
if ( key_hpos == TOUT ) {
xright -= key_col_wth*(key_cols-1) + key_col_wth - 2*(t->h_char);
}
xleft += t->xmax * xoffset;
xright += t->xmax * xoffset;
ytop += t->ymax * yoffset;
ybot += t->ymax * yoffset;
xmiddle = (xright + xleft) / 2;
ymiddle = (ytop + ybot) / 2;
/* HBB 980308: sigh... another 16bit glitch: on term's with more than
* 8000 pixels in either direction, these calculations produce garbage
* results if done in (16bit) ints */
xscaler = (xright - xleft) *4 / 7; /* HBB: Magic number alert! */
yscaler = ((ytop - ybot) * 4L) / 7L;
}
#if 0
/* not used ; anyway, should be done using bitshifts and squares,
* rather than iteratively
*/
static double dbl_raise(x,y)
double x;
int y;
{
register int i = ABS(y);
double val = 1.0;
while (--i >= 0)
val *= x;
if (y < 0 ) return (1.0/val);
return(val);
}
#endif
/* we precalculate features of the key, to save lots of nested
* ifs in code - x,y = user supplied or computed position of key
* taken to be inner edge of a line sample
*/
static int key_sample_left; /* offset from x for left of line sample */
static int key_sample_right; /* offset from x for right of line sample */
static int key_point_offset; /* offset from x for point sample */
static int key_text_left; /* offset from x for left-justified text */
static int key_text_right; /* offset from x for right-justified text */
static int key_size_left; /* distance from x to left edge of box */
static int key_size_right; /* distance from x to right edge of box */
void do_3dplot(plots, pcount)
struct surface_points *plots;
int pcount; /* count of plots in linked list */
{
struct termentry *t = term;
int surface;
struct surface_points *this_plot = NULL;
unsigned int xl, yl;
int linetypeOffset = 0;
double ztemp, temp;
struct text_label *this_label;
struct arrow_def *this_arrow;
TBOOLEAN scaling;
transform_matrix mat;
int key_count;
char ss[MAX_LINE_LEN+1], *s, *e;
/* Initiate transformation matrix using the global view variables. */
mat_rot_z(surface_rot_z, trans_mat);
mat_rot_x(surface_rot_x, mat);
mat_mult(trans_mat, trans_mat, mat);
mat_scale(surface_scale / 2.0, surface_scale / 2.0, surface_scale / 2.0, mat);
mat_mult(trans_mat, trans_mat, mat);
/* modify min_z/max_z so it will zscale properly. */
ztemp = (z_max3d - z_min3d) / (2.0 * surface_zscale);
temp = (z_max3d + z_min3d) / 2.0;
z_min3d = temp - ztemp;
z_max3d = temp + ztemp;
/* The extrema need to be set even when a surface is not being
* drawn. Without this, gnuplot used to assume that the X and
* Y axis started at zero. -RKC
*/
if (polar)
graph_error("Cannot splot in polar coordinate system.");
/* done in plot3d.c
* if (z_min3d == VERYLARGE || z_max3d == -VERYLARGE ||
* x_min3d == VERYLARGE || x_max3d == -VERYLARGE ||
* y_min3d == VERYLARGE || y_max3d == -VERYLARGE)
* graph_error("all points undefined!");
*/
/* If we are to draw the bottom grid make sure zmin is updated properly. */
if (xtics || ytics || work_grid.l_type) {
base_z = z_min3d - (z_max3d - z_min3d) * ticslevel;
if (ticslevel >= 0)
floor_z = base_z;
else
floor_z = z_min3d;
if (ticslevel < -1)
ceiling_z = base_z;
else
ceiling_z = z_max3d;
} else {
floor_z = base_z = z_min3d;
ceiling_z = z_max3d;
}
/* see comment accompanying similar tests of x_min/x_max and y_min/y_max */
/* in graphics.c:do_plot(), for history/rationale of these tests */
if (x_min3d == x_max3d)
graph_error("x_min3d should not equal x_max3d!");
if (y_min3d == y_max3d)
graph_error("y_min3d should not equal y_max3d!");
if (z_min3d == z_max3d)
graph_error("z_min3d should not equal z_max3d!");
#ifndef LITE
if (hidden3d) {
struct surface_points *plot;
int p = 0;
/* Verify data is hidden line removable - grid based. */
for (plot = plots; ++p <= pcount; plot = plot->next_sp) {
if (plot->plot_type == DATA3D && !plot->has_grid_topology){
fprintf(stderr,"Notice: Cannot remove hidden lines from non grid data\n");
return;
}
}
}
#endif /* not LITE */
term_start_plot();
screen_ok = FALSE;
scaling = (*t->scale)(xsize, ysize);
/* now compute boundary for plot (xleft, xright, ytop, ybot) */
boundary3d(scaling,plots,pcount);
/* SCALE FACTORS */
zscale3d = 2.0/(ceiling_z - floor_z);
yscale3d = 2.0/(y_max3d - y_min3d);
xscale3d = 2.0/(x_max3d - x_min3d);
term_apply_lp_properties(&border_lp); /* border linetype */
/* PLACE TITLE */
if (*title.text != 0) {
strcpy(ss, title.text);
write_multiline( (unsigned int)((xleft+xright)/2+title.xoffset*t->h_char),
(unsigned int)(ytop+(titlelin+title.yoffset)*(t->h_char)),
ss, CENTRE, JUST_TOP, 0, title.font);
}
/* PLACE TIMEDATE */
if (*timelabel.text) {
char str[MAX_LINE_LEN+1];
time_t now;
unsigned int x = t->v_char + timelabel.xoffset * t->h_char;
unsigned int y = timelabel_bottom ?
yoffset*ymax + (timelabel.yoffset+1) * t->v_char :
ytop + (timelabel.yoffset-1) * t->v_char;
time(&now);
strftime(str, MAX_LINE_LEN, timelabel.text, localtime(&now));
if (timelabel_rotate && (*t->text_angle)(1))
{
if(timelabel_bottom)
write_multiline(x,y,str,LEFT, JUST_TOP, 1, timelabel.font);
else
write_multiline(x,y,str,RIGHT, JUST_TOP, 1, timelabel.font);
(*t->text_angle)(0);
}
else
{
if(timelabel_bottom)
write_multiline(x,y,str,LEFT, JUST_BOT, 0, timelabel.font);
else
write_multiline(x,y,str,LEFT, JUST_TOP, 0, timelabel.font);
}
}
/* PLACE LABELS */
for (this_label = first_label; this_label != NULL;
this_label = this_label->next ) {
unsigned int x,y;
map_position(&this_label->place, &x, &y, "label");
strcpy(ss, this_label->text);
if(this_label->rotate && (*t->text_angle)(1)) {
write_multiline( x,y, this_label->text, this_label->pos, CENTRE, 1, this_label->font);
(*t->text_angle)(0);
} else {
write_multiline( x,y, this_label->text, this_label->pos, CENTRE, 0, this_label->font);
}
}
/* PLACE ARROWS */
for (this_arrow = first_arrow; this_arrow != NULL;
this_arrow = this_arrow->next ) {
unsigned int sx,sy,ex,ey;
map_position(&this_arrow->start, &sx, &sy, "arrow");
map_position(&this_arrow->end, &ex, &ey, "arrow");
term_apply_lp_properties(&(this_arrow->lp_properties));
(*t->arrow)(sx, sy, ex, ey, this_arrow->head);
}
#ifndef LITE
if (hidden3d && draw_surface) {
init_hidden_line_removal();
reset_hidden_line_removal();
hidden_active = TRUE;
}
#endif /* not LITE */
/* WORK OUT KEY SETTINGS AND DO KEY TITLE / BOX */
if (key_reverse) {
key_sample_left = -key_sample_width;
key_sample_right = 0;
key_text_left = t->h_char;
key_text_right = (t->h_char)*(max_ptitl_len+1);
key_size_right = (t->h_char)*(max_ptitl_len+2+key_width_fix);
key_size_left = (t->h_char) + key_sample_width;
} else {
key_sample_left = 0;
key_sample_right = key_sample_width;
key_text_left = -(int)((t->h_char)*(max_ptitl_len+1));
key_text_right = -(int)(t->h_char);
key_size_left = (t->h_char)*(max_ptitl_len+2+key_width_fix);
key_size_right = (t->h_char)+key_sample_width;
}
key_point_offset = (key_sample_left + key_sample_right)/2;
if (key == -1) {
if ( key_vpos == TUNDER ) {
#if 0
yl = yoffset * t->ymax + (key_rows) * key_entry_height + (ktitle_lines+2)*t->v_char;
xl = max_ptitl_len * 1000/( key_sample_width/(t->h_char) + max_ptitl_len + 2);
xl *= (xright - xleft)/key_cols;
xl /= 1000;
xl += xleft;
#else
/* maximise no cols, limited by label-length */
key_cols = (int)(xright - xleft)/key_col_wth;
key_rows = (int)(ptitl_cnt+key_cols-1)/key_cols;
/* now calculate actual no cols depending on no rows */
key_cols = (int)(ptitl_cnt+key_rows-1)/key_rows;
key_col_wth = (int)(xright - xleft)/key_cols;
/* we divide into columns, then centre in column by considering ratio
* of key_left_size to key_right_size
* key_size_left/(key_size_left+key_size_right) * (xright-xleft)/key_cols
* do one integer division to maximise accuracy (hope we dont overflow !)
*/
xl = xleft + ((xright-xleft)*key_size_left) / (key_cols*(key_size_left+key_size_right));
yl = yoffset * t->ymax + (key_rows) * key_entry_height + (ktitle_lines+2)*t->v_char;
#endif
} else {
if ( key_vpos == TTOP ) {
yl = ytop - (t->v_tic) - t->v_char;
} else {
yl = ybot + (t->v_tic) + key_entry_height*key_rows + ktitle_lines*t->v_char;
}
if ( key_hpos == TOUT ) {
/* keys outside plot border (right) */
xl = xright + (t->h_tic) + key_size_left;
} else if ( key_hpos == TLEFT ) {
xl = xleft + (t->h_tic) + key_size_left;
} else {
xl = xright - key_size_right - key_col_wth*(key_cols-1);
}
}
yl_ref = yl - ktitle_lines * (t->v_char);
}
if (key == 1) {
map_position(&key_user_pos, &xl, &yl, "key");
}
if (key && key_box.l_type>-3) {
int yt = yl;
int yb = yl - key_entry_height*(key_rows-ktitle_lines) - ktitle_lines*t->v_char;
int key_xr = xl + key_col_wth * (key_cols-1) + key_size_right;
/* key_rows seems to contain title at this point ??? */
term_apply_lp_properties(&key_box);
(*t->move)(xl-key_size_left,yb);
(*t->vector)(xl-key_size_left,yt);
(*t->vector)(key_xr,yt);
(*t->vector)(key_xr,yb);
(*t->vector)(xl-key_size_left,yb);
/* draw a horizontal line between key title and first entry */ /* JFi */
(*t->move)(xl-key_size_left,yt - (ktitle_lines) * t->v_char); /* JFi */
(*t->vector)(xl+key_size_right,yt - (ktitle_lines) * t->v_char); /* JFi */
}
/* DRAW SURFACES AND CONTOURS */
#ifndef LITE
if (hidden3d && draw_surface) plot3d_hidden(plots,pcount);
#endif /* not LITE */
/* KEY TITLE */
if (key != 0 && strlen(key_title)) {
sprintf(ss,"%s\n",key_title);
s = ss;
yl -= t->v_char/2;
while( (e = (char *)strchr(s,'\n')) != NULL ) {
*e = '\0';
if ( key_just == JLEFT) {
(*t->justify_text)(LEFT);
(*t->put_text)(xl+key_text_left,yl,s);
} else {
if ((*t->justify_text)(RIGHT)) {
(*t->put_text)(xl+key_text_right,
yl,s);
} else {
int x = xl+key_text_right-(t->h_char)*strlen(s);
if (inrange(x,xleft, xright))
(*t->put_text)(x,yl,s);
}
}
s = ++e;
yl -= t->v_char;
}
yl += t->v_char/2;
}
key_count = 0;
yl_ref = yl -= key_entry_height/2; /* centralise the keys */
#define NEXT_KEY_LINE() \
if ( ++key_count >= key_rows ) { \
yl = yl_ref; xl += key_col_wth; key_count = 0; \
} else \
yl -= key_entry_height
this_plot = plots;
for (surface = 0;
surface < pcount;
this_plot = this_plot->next_sp, surface++) {
#ifndef LITE
if ( hidden3d )
hidden_no_update = FALSE;
#endif /* not LITE */
if (draw_surface)
{
int lkey = (key != 0 && this_plot->title && this_plot->title[0]);
term_apply_lp_properties(&(this_plot->lp_properties));
#ifndef LITE
if (hidden3d) {
hidden_line_type_above = this_plot->lp_properties.l_type;
hidden_line_type_below = this_plot->lp_properties.l_type + 1;
}
#endif /* not LITE */
if (lkey) {
key_text(xl, yl, this_plot->title);
}
switch(this_plot->plot_style) {
case BOXES: /* can't do boxes in 3d yet so use impulses */
case IMPULSES: {
if (lkey) {
key_sample_line(xl,yl);
}
if (!(hidden3d && draw_surface))
plot3d_impulses(this_plot);
break;
}
case STEPS: /* HBB: I think these should be here */
case FSTEPS:
case HISTEPS:
case LINES: {
if (lkey) {
key_sample_line(xl,yl);
}
if (!(hidden3d && draw_surface))
plot3d_lines(this_plot);
break;
}
case YERRORBARS: /* ignored; treat like points */
case XERRORBARS: /* ignored; treat like points */
case XYERRORBARS: /* ignored; treat like points */
case BOXXYERROR: /* HBB: ignore these as well */
case BOXERROR:
case CANDLESTICKS: /* HBB: dito */
case FINANCEBARS:
case VECTOR:
case POINTSTYLE:
if (lkey && !clip_point(xl+key_point_offset,yl)) {
key_sample_point(xl,yl,this_plot->lp_properties.p_type);
}
if (!(hidden3d && draw_surface))
plot3d_points(this_plot);
break;
case LINESPOINTS:
/* put lines */
if (lkey)
key_sample_line(xl,yl);
if (!(hidden3d && draw_surface))
plot3d_lines(this_plot);
/* put points */
if (lkey && !clip_point(xl+key_point_offset,yl))
key_sample_point(xl,yl,this_plot->lp_properties.p_type);
if (!(hidden3d && draw_surface))
plot3d_points(this_plot);
break;
case DOTS:
if (lkey) {
if (key == 1) {
if (!clip_point(xl+key_point_offset,yl))
(*t->point)(xl+key_point_offset,yl, -1);
} else {
(*t->point)(xl+key_point_offset,yl, -1);
/* (*t->point)(xl+2*(t->h_char),yl, -1); */
}
}
if (!(hidden3d && draw_surface))
plot3d_dots(this_plot);
break;
} /* switch(plot-style) */
/* move key on a line */
if (lkey) {
NEXT_KEY_LINE();
}
} /* draw_surface */
#ifndef LITE
if ( hidden3d ) {
hidden_no_update = TRUE;
hidden_line_type_above = this_plot->lp_properties.l_type + (hidden3d ? 2 : 1);
hidden_line_type_below = this_plot->lp_properties.l_type + (hidden3d ? 2 : 1);
}
#endif /* not LITE */
if (draw_contour && this_plot->contours != NULL) {
struct gnuplot_contours *cntrs = this_plot->contours;
term_apply_lp_properties(&(this_plot->lp_properties));
(*t->linetype)(this_plot->lp_properties.l_type + (hidden3d ? 2 : 1));
if (key != 0 && this_plot->title && this_plot->title[0]
&& !draw_surface && !label_contours)
{
/* unlabelled contours but no surface : put key entry in now */
key_text(xl,yl, this_plot->title);
switch(this_plot->plot_style) {
case IMPULSES:
case LINES:
case BOXES: /* HBB: I think these should be here... */
case STEPS:
case FSTEPS:
case HISTEPS:
key_sample_line(xl,yl);
break;
case YERRORBARS: /* ignored; treat like points */
case XERRORBARS: /* ignored; treat like points */
case XYERRORBARS: /* ignored; treat like points */
case BOXERROR: /* HBB: ignore these as well */
case BOXXYERROR:
case CANDLESTICKS: /* HBB: dito */
case FINANCEBARS:
case VECTOR:
case POINTSTYLE:
key_sample_point(xl,yl,this_plot->lp_properties.p_type);
break;
case LINESPOINTS:
key_sample_line(xl,yl);
break;
case DOTS:
key_sample_point(xl,yl,-1);
break;
}
}
linetypeOffset = this_plot->lp_properties.l_type + (hidden3d ? 2 : 1);
while (cntrs) {
if(label_contours && cntrs->isNewLevel) {
(*t->linetype)(linetypeOffset++);
if (key) {
#ifndef LITE
if(hidden3d) hidden_line_type_below = hidden_line_type_above = linetypeOffset-1;
#endif /* not LITE */
key_text(xl,yl,cntrs->label);
switch(this_plot->plot_style) {
case IMPULSES:
case LINES:
case LINESPOINTS:
case BOXES: /* HBB: these should be treated as well... */
case STEPS:
case FSTEPS:
case HISTEPS:
key_sample_line(xl,yl);
break;
case YERRORBARS: /* ignored; treat like points */
case XERRORBARS: /* ignored; treat like points */
case XYERRORBARS: /* ignored; treat like points */
case BOXERROR: /* HBB: treat these likewise */
case BOXXYERROR:
case CANDLESTICKS: /* HBB: dito */
case FINANCEBARS:
case VECTOR:
case POINTSTYLE:
key_sample_point(xl,yl,this_plot->lp_properties.p_type);
break;
case DOTS:
key_sample_point(xl,yl,-1);
break;
} /* switch */
NEXT_KEY_LINE();
} /* key */
} /* label_contours */
/* now draw the contour */
switch(this_plot->plot_style) {
case IMPULSES:
case BOXES: /* HBB: this should also be treated somehow */
cntr3d_impulses(cntrs, this_plot);
break;
case LINES:
case STEPS: /* HBB: these should also be handled, I think */
case FSTEPS:
case HISTEPS:
cntr3d_lines(cntrs);
break;
case YERRORBARS: /* ignored; treat like points */
case XERRORBARS: /* ignored; treat like points */
case XYERRORBARS: /* ignored; treat like points */
case BOXERROR: /* HBB: ignore these too... */
case BOXXYERROR:
case CANDLESTICKS: /* HBB: dito */
case FINANCEBARS:
case VECTOR:
case POINTSTYLE:
cntr3d_points(cntrs, this_plot);
break;
case LINESPOINTS:
cntr3d_lines(cntrs);
cntr3d_points(cntrs, this_plot);
break;
case DOTS:
cntr3d_dots(cntrs);
break;
} /*switch*/
cntrs = cntrs->next;
} /* loop over contours */
} /* draw contours */
} /* loop over surfaces */