FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gnuplot-old/src/plot3d.c at branch-4-2-stable · gnuplot/gnuplot-old · GitHub
gnuplot
gnuplot-old
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gnuplot-old
/
src
/
plot3d.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
2054 lines (1768 loc) · 60.8 KB
Breadcrumbs
gnuplot-old
/
src
/
plot3d.c
Copy path
File metadata and controls
2054 lines (1768 loc) · 60.8 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
() {
return
RCSid
(
"$Id: plot3d.c,v 1.131.2.6 2008/03/20 09:39:46 sfeam Exp $"
); }
#endif
/* GNUPLOT - plot3d.c */
/*[
* Copyright 1986 - 1993, 1998, 2004 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.
]*/
#include
"plot3d.h"
#include
"gp_types.h"
#include
"alloc.h"
#include
"axis.h"
#include
"binary.h"
#include
"command.h"
#include
"contour.h"
#include
"datafile.h"
#include
"eval.h"
#include
"graph3d.h"
#include
"misc.h"
#include
"parse.h"
#include
"setshow.h"
#include
"term_api.h"
#include
"util.h"
#include
"pm3d.h"
#ifdef
BINARY_DATA_FILE
#include
"plot.h"
#endif
#ifdef
EAM_DATASTRINGS
#include
"plot2d.h"
/* Only for store_label() */
#endif
#ifdef
THIN_PLATE_SPLINES_GRID
# include
"matrix.h"
#endif
#ifndef
_Windows
# include
"help.h"
#endif
/* global variables exported by this module */
t_data_mapping
mapping3d
=
MAP3D_CARTESIAN
;
int
dgrid3d_row_fineness
=
10
;
int
dgrid3d_col_fineness
=
10
;
int
dgrid3d_norm_value
=
1
;
TBOOLEAN
dgrid3d
=
FALSE;
/* static prototypes */
static
void
calculate_set_of_isolines
__PROTO
((
AXIS_INDEX
value_axis
,
TBOOLEAN
cross
,
struct
iso_curve
*
*
this_iso
,
AXIS_INDEX
iso_axis
,
double
iso_min
,
double
iso_step
,
int
num_iso_to_use
,
AXIS_INDEX
sam_axis
,
double
sam_min
,
double
sam_step
,
int
num_sam_to_use
,
TBOOLEAN
need_palette
));
static
void
get_3ddata
__PROTO
((
struct
surface_points
*
this_plot
));
static
void
print_3dtable
__PROTO
((
int
pcount
));
static
void
eval_3dplots
__PROTO
((
void
));
static
void
grid_nongrid_data
__PROTO
((
struct
surface_points
*
this_plot
));
static
void
parametric_3dfixup
__PROTO
((
struct
surface_points
*
start_plot
,
int
*
plot_num
));
static
struct
surface_points
*
sp_alloc
__PROTO
((
int
num_samp_1
,
int
num_iso_1
,
int
num_samp_2
,
int
num_iso_2
));
static
void
sp_replace
__PROTO
((
struct
surface_points
*
sp
,
int
num_samp_1
,
int
num_iso_1
,
int
num_samp_2
,
int
num_iso_2
));
#ifdef
THIN_PLATE_SPLINES_GRID
static
double
splines_kernel
__PROTO
((
double
h
));
#endif
/* the curves/surfaces of the plot */
struct
surface_points
*
first_3dplot
=
NULL
;
static
struct
udft_entry
plot_func
;
int
plot3d_num
=
0
;
/* HBB 20000508: moved these functions to the only module that uses them
* so they can be turned 'static' */
/*
* sp_alloc() allocates a surface_points structure that can hold 'num_iso_1'
* iso-curves with 'num_samp_2' samples and 'num_iso_2' iso-curves with
* 'num_samp_1' samples.
* If, however num_iso_2 or num_samp_1 is zero no iso curves are allocated.
*/
static
struct
surface_points
*
sp_alloc
(
int
num_samp_1
,
int
num_iso_1
,
int
num_samp_2
,
int
num_iso_2
)
{
struct
lp_style_type
default_lp_properties
=
DEFAULT_LP_STYLE_TYPE
;
struct
surface_points
*
sp
=
gp_alloc
(
sizeof
(
*
sp
),
"surface"
);
memset
(
sp
,
0
,
sizeof
(
struct
surface_points
));
/* Initialize various fields */
sp
->
lp_properties
=
default_lp_properties
;
default_arrow_style
(
&
(
sp
->
arrow_properties
));
if
(
num_iso_2
>
0
&&
num_samp_1
>
0
) {
int
i
;
struct
iso_curve
*
icrv
;
for
(
i
=
0
;
i
<
num_iso_1
;
i
++
) {
icrv
=
iso_alloc
(
num_samp_2
);
icrv
->
next
=
sp
->
iso_crvs
;
sp
->
iso_crvs
=
icrv
;
}
for
(
i
=
0
;
i
<
num_iso_2
;
i
++
) {
icrv
=
iso_alloc
(
num_samp_1
);
icrv
->
next
=
sp
->
iso_crvs
;
sp
->
iso_crvs
=
icrv
;
}
}
return
(
sp
);
}
/*
* sp_replace() updates a surface_points structure so it can hold 'num_iso_1'
* iso-curves with 'num_samp_2' samples and 'num_iso_2' iso-curves with
* 'num_samp_1' samples.
* If, however num_iso_2 or num_samp_1 is zero no iso curves are allocated.
*/
static
void
sp_replace
(
struct
surface_points
*
sp
,
int
num_samp_1
,
int
num_iso_1
,
int
num_samp_2
,
int
num_iso_2
)
{
int
i
;
struct
iso_curve
*
icrv
,
*
icrvs
=
sp
->
iso_crvs
;
while
(
icrvs
) {
icrv
=
icrvs
;
icrvs
=
icrvs
->
next
;
iso_free
(
icrv
);
}
sp
->
iso_crvs
=
NULL
;
if
(
num_iso_2
>
0
&&
num_samp_1
>
0
) {
for
(
i
=
0
;
i
<
num_iso_1
;
i
++
) {
icrv
=
iso_alloc
(
num_samp_2
);
icrv
->
next
=
sp
->
iso_crvs
;
sp
->
iso_crvs
=
icrv
;
}
for
(
i
=
0
;
i
<
num_iso_2
;
i
++
) {
icrv
=
iso_alloc
(
num_samp_1
);
icrv
->
next
=
sp
->
iso_crvs
;
sp
->
iso_crvs
=
icrv
;
}
}
else
sp
->
iso_crvs
=
NULL
;
}
/*
* sp_free() releases any memory which was previously malloc()'d to hold
* surface points.
*/
/* HBB 20000506: don't risk stack havoc by recursion, use iterative list
* cleanup unstead */
void
sp_free
(
struct
surface_points
*
sp
)
{
while
(
sp
) {
struct
surface_points
*
next
=
sp
->
next_sp
;
if
(
sp
->
title
)
free
(
sp
->
title
);
while
(
sp
->
contours
) {
struct
gnuplot_contours
*
next_cntrs
=
sp
->
contours
->
next
;
free
(
sp
->
contours
->
coords
);
free
(
sp
->
contours
);
sp
->
contours
=
next_cntrs
;
}
while
(
sp
->
iso_crvs
) {
struct
iso_curve
*
next_icrvs
=
sp
->
iso_crvs
->
next
;
iso_free
(
sp
->
iso_crvs
);
sp
->
iso_crvs
=
next_icrvs
;
}
#ifdef
EAM_DATASTRINGS
if
(
sp
->
labels
) {
free_labels
(
sp
->
labels
);
sp
->
labels
=
(
struct
text_label
*
)
NULL
;
}
#endif
free
(
sp
);
sp
=
next
;
}
}
/* support for dynamic size of input line */
void
plot3drequest
()
/*
* in the parametric case we would say splot [u= -Pi:Pi] [v= 0:2*Pi] [-1:1]
* [-1:1] [-1:1] sin(v)*cos(u),sin(v)*cos(u),sin(u) in the non-parametric
* case we would say only splot [x= -2:2] [y= -5:5] sin(x)*cos(y)
*
*/
{
int
dummy_token0
=
-1
,
dummy_token1
=
-1
;
AXIS_INDEX
u_axis
,
v_axis
;
is_3d_plot
=
TRUE;
/* change view to become map if requested by 'set view map' */
if
(
splot_map
==
TRUE)
splot_map_activate
();
if
(
parametric
&&
strcmp
(
set_dummy_var
[
0
],
"t"
)
==
0
) {
strcpy
(
set_dummy_var
[
0
],
"u"
);
strcpy
(
set_dummy_var
[
1
],
"v"
);
}
/* put stuff into arrays to simplify access */
AXIS_INIT3D
(
FIRST_X_AXIS
,
0
,
0
);
AXIS_INIT3D
(
FIRST_Y_AXIS
,
0
,
0
);
AXIS_INIT3D
(
FIRST_Z_AXIS
,
0
,
1
);
AXIS_INIT3D
(
U_AXIS
,
1
,
0
);
AXIS_INIT3D
(
V_AXIS
,
1
,
0
);
AXIS_INIT3D
(
COLOR_AXIS
,
0
,
1
);
if
(!
term
)
/* unknown */
int_error
(
c_token
,
"use 'set term' to set terminal type first"
);
u_axis
=
(
parametric
?
U_AXIS
:
FIRST_X_AXIS
);
v_axis
=
(
parametric
?
V_AXIS
:
FIRST_Y_AXIS
);
PARSE_NAMED_RANGE
(
u_axis
,
dummy_token0
);
if
(
splot_map
==
TRUE
&&
!
parametric
)
/* v_axis==FIRST_Y_AXIS */
splot_map_deactivate
();
PARSE_NAMED_RANGE
(
v_axis
,
dummy_token1
);
if
(
splot_map
==
TRUE
&&
!
parametric
)
/* v_axis==FIRST_Y_AXIS */
splot_map_activate
();
if
(
parametric
) {
PARSE_RANGE
(
FIRST_X_AXIS
);
if
(
splot_map
==
TRUE)
splot_map_deactivate
();
PARSE_RANGE
(
FIRST_Y_AXIS
);
if
(
splot_map
==
TRUE)
splot_map_activate
();
}
/* parametric */
PARSE_RANGE
(
FIRST_Z_AXIS
);
CHECK_REVERSE
(
FIRST_X_AXIS
);
CHECK_REVERSE
(
FIRST_Y_AXIS
);
CHECK_REVERSE
(
FIRST_Z_AXIS
);
/* use the default dummy variable unless changed */
if
(
dummy_token0
>=
0
)
copy_str
(
c_dummy_var
[
0
],
dummy_token0
,
MAX_ID_LEN
);
else
(
void
)
strcpy
(
c_dummy_var
[
0
],
set_dummy_var
[
0
]);
if
(
dummy_token1
>=
0
)
copy_str
(
c_dummy_var
[
1
],
dummy_token1
,
MAX_ID_LEN
);
else
(
void
)
strcpy
(
c_dummy_var
[
1
],
set_dummy_var
[
1
]);
eval_3dplots
();
}
#ifdef
THIN_PLATE_SPLINES_GRID
static
double
splines_kernel
(
double
h
)
{
#if
0
/* this is normaly not useful ... */
h
=
fabs
(
h
);
if
(
h
!=
0.0
) {
#else
if
(
h
>
0
) {
#endif
return
h
*
h
*
log
(
h
);
}
else
{
return
0
;
}
}
#endif
static
void
grid_nongrid_data
(
struct
surface_points
*
this_plot
)
{
int
i
,
j
,
k
;
double
x
,
y
,
z
,
w
,
dx
,
dy
,
xmin
,
xmax
,
ymin
,
ymax
;
struct
iso_curve
*
old_iso_crvs
=
this_plot
->
iso_crvs
;
struct
iso_curve
*
icrv
,
*
oicrv
,
*
oicrvs
;
#ifdef
THIN_PLATE_SPLINES_GRID
double
*
b
,
*
*
K
,
*
xx
,
*
yy
,
*
zz
,
d
;
int
*
indx
,
numpoints
;
#endif
/* Compute XY bounding box on the original data. */
/* FIXME HBB 20010424: Does this make any sense? Shouldn't we just
* use whatever the x and y ranges have been found to be, and
* that's that? The largest difference this is going to make is if
* we plot a datafile that doesn't span the whole x/y range
* used. Do we want a dgrid3d over the actual data rectangle, or
* over the xrange/yrange area? */
xmin
=
xmax
=
old_iso_crvs
->
points
[
0
].
x
;
ymin
=
ymax
=
old_iso_crvs
->
points
[
0
].
y
;
for
(
icrv
=
old_iso_crvs
;
icrv
!=
NULL
;
icrv
=
icrv
->
next
) {
struct
coordinate
GPHUGE
*
points
=
icrv
->
points
;
for
(
i
=
0
;
i
<
icrv
->
p_count
;
i
++
,
points
++
) {
/* HBB 20010424: avoid crashing for undefined input */
if
(
points
->
type
==
UNDEFINED
)
continue
;
if
(
xmin
>
points
->
x
)
xmin
=
points
->
x
;
if
(
xmax
<
points
->
x
)
xmax
=
points
->
x
;
if
(
ymin
>
points
->
y
)
ymin
=
points
->
y
;
if
(
ymax
<
points
->
y
)
ymax
=
points
->
y
;
}
}
dx
=
(
xmax
-
xmin
) / (
dgrid3d_col_fineness
-
1
);
dy
=
(
ymax
-
ymin
) / (
dgrid3d_row_fineness
-
1
);
/* Create the new grid structure, and compute the low pass filtering from
* non grid to grid structure.
*/
this_plot
->
iso_crvs
=
NULL
;
this_plot
->
num_iso_read
=
dgrid3d_col_fineness
;
this_plot
->
has_grid_topology
=
TRUE;
#ifdef
THIN_PLATE_SPLINES_GRID
numpoints
=
0
;
for
(
oicrv
=
old_iso_crvs
;
oicrv
!=
NULL
;
oicrv
=
oicrv
->
next
) {
numpoints
+=
oicrv
->
p_count
;
}
xx
=
gp_alloc
(
sizeof
(
xx
[
0
])
*
(
numpoints
+
3
)
*
(
numpoints
+
8
),
"thin plate splines in dgrid3d"
);
/* the memory needed is not really (n+3)*(n+8) for now,
but might be if I take into account errors ... */
K
=
gp_alloc
(
sizeof
(
K
[
0
])
*
(
numpoints
+
3
),
"matrix : thin plate splines 2d"
);
yy
=
xx
+
numpoints
;
zz
=
yy
+
numpoints
;
b
=
zz
+
numpoints
;
/* HBB 20010424: Count actual input points without the UNDEFINED
* ones, as we copy them */
numpoints
=
0
;
for
(
oicrv
=
old_iso_crvs
;
oicrv
!=
NULL
;
oicrv
=
oicrv
->
next
) {
struct
coordinate
GPHUGE
*
opoints
=
oicrv
->
points
;
for
(
k
=
0
;
k
<
oicrv
->
p_count
;
k
++
,
opoints
++
) {
/* HBB 20010424: avoid crashing for undefined input */
if
(
opoints
->
type
==
UNDEFINED
)
continue
;
xx
[
numpoints
]
=
opoints
->
x
;
yy
[
numpoints
]
=
opoints
->
y
;
zz
[
numpoints
]
=
opoints
->
z
;
numpoints
++
;
}
}
for
(
i
=
0
;
i
<
numpoints
+
3
;
i
++
) {
K
[
i
]
=
b
+
(
numpoints
+
3
)
*
(
i
+
1
);
}
for
(
i
=
0
;
i
<
numpoints
;
i
++
) {
for
(
j
=
i
+
1
;
j
<
numpoints
;
j
++
) {
double
dx
=
xx
[
i
]
-
xx
[
j
],
dy
=
yy
[
i
]
-
yy
[
j
];
K
[
i
][
j
]
=
K
[
j
][
i
]
=
-
splines_kernel
(
sqrt
(
dx
*
dx
+
dy
*
dy
));
}
K
[
i
][
i
]
=
0.0
;
/* here will come the weights for errors */
b
[
i
]
=
zz
[
i
];
}
for
(
i
=
0
;
i
<
numpoints
;
i
++
) {
K
[
i
][
numpoints
]
=
K
[
numpoints
][
i
]
=
1.0
;
K
[
i
][
numpoints
+
1
]
=
K
[
numpoints
+
1
][
i
]
=
xx
[
i
];
K
[
i
][
numpoints
+
2
]
=
K
[
numpoints
+
2
][
i
]
=
yy
[
i
];
}
b
[
numpoints
]
=
0.0
;
b
[
numpoints
+
1
]
=
0.0
;
b
[
numpoints
+
2
]
=
0.0
;
K
[
numpoints
][
numpoints
]
=
0.0
;
K
[
numpoints
][
numpoints
+
1
]
=
0.0
;
K
[
numpoints
][
numpoints
+
2
]
=
0.0
;
K
[
numpoints
+
1
][
numpoints
]
=
0.0
;
K
[
numpoints
+
1
][
numpoints
+
1
]
=
0.0
;
K
[
numpoints
+
1
][
numpoints
+
2
]
=
0.0
;
K
[
numpoints
+
2
][
numpoints
]
=
0.0
;
K
[
numpoints
+
2
][
numpoints
+
1
]
=
0.0
;
K
[
numpoints
+
2
][
numpoints
+
2
]
=
0.0
;
indx
=
gp_alloc
(
sizeof
(
indx
[
0
])
*
(
numpoints
+
3
),
"indexes lu"
);
/* actually, K is *not* positive definite, but
has only non zero real eigenvalues ->
we can use an lu_decomp safely */
lu_decomp
(
K
,
numpoints
+
3
,
indx
,
&
d
);
lu_backsubst
(
K
,
numpoints
+
3
,
indx
,
b
);
#endif
/* THIN_PLATE_SPLINES_GRID */
for
(
i
=
0
,
x
=
xmin
;
i
<
dgrid3d_col_fineness
;
i
++
,
x
+=
dx
) {
struct
coordinate
GPHUGE
*
points
;
icrv
=
iso_alloc
(
dgrid3d_row_fineness
+
1
);
icrv
->
p_count
=
dgrid3d_row_fineness
;
icrv
->
next
=
this_plot
->
iso_crvs
;
this_plot
->
iso_crvs
=
icrv
;
points
=
icrv
->
points
;
for
(
j
=
0
,
y
=
ymin
;
j
<
dgrid3d_row_fineness
;
j
++
,
y
+=
dy
,
points
++
) {
z
=
w
=
0.0
;
/* as soon as ->type is changed to UNDEFINED, break out of
* two inner loops! */
points
->
type
=
INRANGE
;
#ifdef
THIN_PLATE_SPLINES_GRID
z
=
b
[
numpoints
];
for
(
k
=
0
;
k
<
numpoints
;
k
++
) {
double
dx
=
xx
[
k
]
-
x
,
dy
=
yy
[
k
]
-
y
;
z
=
z
-
b
[
k
]
*
splines_kernel
(
sqrt
(
dx
*
dx
+
dy
*
dy
));
}
z
=
z
+
b
[
numpoints
+
1
]
*
x
+
b
[
numpoints
+
2
]
*
y
;
#else
for
(
oicrv
=
old_iso_crvs
;
oicrv
!=
NULL
;
oicrv
=
oicrv
->
next
) {
struct
coordinate
GPHUGE
*
opoints
=
oicrv
->
points
;
for
(
k
=
0
;
k
<
oicrv
->
p_count
;
k
++
,
opoints
++
) {
double
dist
,
dist_x
=
fabs
(
opoints
->
x
-
x
),
dist_y
=
fabs
(
opoints
->
y
-
y
);
switch
(
dgrid3d_norm_value
) {
case
1
:
dist
=
dist_x
+
dist_y
;
break
;
case
2
:
dist
=
dist_x
*
dist_x
+
dist_y
*
dist_y
;
break
;
case
4
:
dist
=
dist_x
*
dist_x
+
dist_y
*
dist_y
;
dist
*=
dist
;
break
;
case
8
:
dist
=
dist_x
*
dist_x
+
dist_y
*
dist_y
;
dist
*=
dist
;
dist
*=
dist
;
break
;
case
16
:
dist
=
dist_x
*
dist_x
+
dist_y
*
dist_y
;
dist
*=
dist
;
dist
*=
dist
;
dist
*=
dist
;
break
;
default
:
dist
=
pow
(
dist_x
, (
double
)
dgrid3d_norm_value
)
+
pow
(
dist_y
, (
double
)
dgrid3d_norm_value
);
break
;
}
/* The weight of this point is inverse proportional
* to the distance.
*/
if
(
dist
==
0.0
) {
/* HBB 981209: revised flagging as undefined */
/* Supporting all those infinities on various
* platforms becomes tiresome, to say the least :-(
* Let's just return the first z where this happens,
* unchanged, and be done with this, period. */
points
->
type
=
UNDEFINED
;
z
=
opoints
->
z
;
w
=
1.0
;
break
;
/* out of inner loop */
}
else
{
dist
=
1.0
/
dist
;
z
+=
opoints
->
z
*
dist
;
w
+=
dist
;
}
}
if
(
points
->
type
!=
INRANGE
)
break
;
/* out of the second-inner loop as well ... */
}
#endif
/* THIN_PLATE_SPLINES_GRID */
/* Now that we've escaped the loops safely, we know that we
* do have a good value in z and w, so we can proceed just as
* if nothing had happened at all. Nice, isn't it? */
points
->
type
=
INRANGE
;
/* HBB 20010424: if log x or log y axis, we don't want to
* log() the value again --> just store it, and trust that
* it's always inrange */
points
->
x
=
x
;
points
->
y
=
y
;
#ifndef
THIN_PLATE_SPLINES_GRID
z
=
z
/
w
;
#endif
STORE_WITH_LOG_AND_UPDATE_RANGE
(
points
->
z
,
z
,
points
->
type
,
z_axis
,
NOOP
,
continue
);
if
(
this_plot
->
pm3d_color_from_column
)
int_error
(
NO_CARET
,
"Gridding of the color column is not implemented"
);
else
{
COLOR_STORE_WITH_LOG_AND_UPDATE_RANGE
(
points
->
CRD_COLOR
,
z
,
points
->
type
,
COLOR_AXIS
,
NOOP
,
continue
);
}
}
}
#ifdef
THIN_PLATE_SPLINES_GRID
free
(
K
);
free
(
xx
);
free
(
indx
);
#endif
/* Delete the old non grid data. */
for
(
oicrvs
=
old_iso_crvs
;
oicrvs
!=
NULL
;) {
oicrv
=
oicrvs
;
oicrvs
=
oicrvs
->
next
;
iso_free
(
oicrv
);
}
}
/* Get 3D data from file, and store into this_plot data
* structure. Takes care of 'set mapping' and 'set dgrid3d'.
*
* Notice: this_plot->token is end of datafile spec, before title etc
* will be moved past title etc after we return */
static
void
get_3ddata
(
struct
surface_points
*
this_plot
)
{
int
xdatum
=
0
;
int
ydatum
=
0
;
int
j
;
double
v
[
MAXDATACOLS
];
int
pt_in_iso_crv
=
0
;
struct
iso_curve
*
this_iso
;
if
(
mapping3d
==
MAP3D_CARTESIAN
) {
/* do this check only, if we have PM3D / PM3D-COLUMN not compiled in */
if
(
df_no_use_specs
==
2
)
int_error
(
this_plot
->
token
,
"Need 1 or 3 columns for cartesian data"
);
/* HBB NEW 20060427: if there's only one, explicit using
* column, it's z data. df_axis[] has to reflect that, so
* df_readline() will expect time/date input. */
if
(
df_no_use_specs
==
1
)
df_axis
[
0
]
=
FIRST_Z_AXIS
;
}
else
{
if
(
df_no_use_specs
==
1
)
int_error
(
this_plot
->
token
,
"Need 2 or 3 columns for polar data"
);
}
this_plot
->
num_iso_read
=
0
;
this_plot
->
has_grid_topology
=
TRUE;
this_plot
->
pm3d_color_from_column
=
FALSE;
/* we ought to keep old memory - most likely case
* is a replot, so it will probably exactly fit into
* memory already allocated ?
*/
if
(
this_plot
->
iso_crvs
!=
NULL
) {
struct
iso_curve
*
icrv
,
*
icrvs
=
this_plot
->
iso_crvs
;
while
(
icrvs
) {
icrv
=
icrvs
;
icrvs
=
icrvs
->
next
;
iso_free
(
icrv
);
}
this_plot
->
iso_crvs
=
NULL
;
}
/* data file is already open */
#ifndef
BINARY_DATA_FILE
/* NO LONGER REQUIRED FOR GENERAL BINARY OR MATRIX BINARY DATA */
if
(
df_matrix
)
xdatum
=
df_3dmatrix
(
this_plot
,
NEED_PALETTE
(
this_plot
));
else
{
#else
if
(
df_matrix
) {
this_plot
->
has_grid_topology
=
TRUE;
}
{
#endif
/*{{{ read surface from text file */
struct
iso_curve
*
local_this_iso
=
iso_alloc
(
samples_1
);
struct
coordinate
GPHUGE
*
cp
;
struct
coordinate
GPHUGE
*
cptail
=
NULL
;
/* Only for VECTOR plots */
double
x
,
y
,
z
;
double
xtail
,
ytail
,
ztail
;
double
color
=
VERYLARGE
;
int
pm3d_color_from_column
=
FALSE;
#define
color_from_column
(
x
) pm3d_color_from_column = x
#ifdef
EAM_DATASTRINGS
if
(
this_plot
->
plot_style
==
LABELPOINTS
)
expect_string
(
4
);
#endif
if
(
this_plot
->
plot_style
==
VECTOR
) {
local_this_iso
->
next
=
iso_alloc
(
samples_1
);
local_this_iso
->
next
->
p_count
=
0
;
}
while
((
j
=
df_readline
(
v
,
MAXDATACOLS
))
!=
DF_EOF
) {
if
(
j
==
DF_SECOND_BLANK
)
break
;
/* two blank lines */
if
(
j
==
DF_FIRST_BLANK
) {
#if
defined(
WITH_IMAGE
)
&&
defined(
BINARY_DATA_FILE
)
/* Images are in a sense similar to isocurves.
* However, the routine for images is written to
* compute the two dimensions of coordinates by
* examining the data alone. That way it can be used
* in the 2D plots, for which there is no isoline
* record. So, toss out isoline information for
* images.
*/
if
((
this_plot
->
plot_style
==
IMAGE
)
||
(
this_plot
->
plot_style
==
RGBIMAGE
))
continue
;
#endif
if
(
this_plot
->
plot_style
==
VECTOR
)
continue
;
/* one blank line */
if
(
pt_in_iso_crv
==
0
) {
if
(
xdatum
==
0
)
continue
;
pt_in_iso_crv
=
xdatum
;
}
if
(
xdatum
>
0
) {
local_this_iso
->
p_count
=
xdatum
;
local_this_iso
->
next
=
this_plot
->
iso_crvs
;
this_plot
->
iso_crvs
=
local_this_iso
;
this_plot
->
num_iso_read
++
;
if
(
xdatum
!=
pt_in_iso_crv
)
this_plot
->
has_grid_topology
=
FALSE;
local_this_iso
=
iso_alloc
(
pt_in_iso_crv
);
xdatum
=
0
;
ydatum
++
;
}
continue
;
}
/* its a data point or undefined */
if
(
xdatum
>=
local_this_iso
->
p_max
) {
/* overflow about to occur. Extend size of points[]
* array. Double the size, and add 1000 points, to
* avoid needlessly small steps. */
iso_extend
(
local_this_iso
,
xdatum
+
xdatum
+
1000
);
if
(
this_plot
->
plot_style
==
VECTOR
) {
iso_extend
(
local_this_iso
->
next
,
xdatum
+
xdatum
+
1000
);
local_this_iso
->
next
->
p_count
=
0
;
}
}
cp
=
local_this_iso
->
points
+
xdatum
;
if
(
this_plot
->
plot_style
==
VECTOR
) {
if
(
j
<
6
) {
cp
->
type
=
UNDEFINED
;
continue
;
}
cptail
=
local_this_iso
->
next
->
points
+
xdatum
;
}
if
(
j
==
DF_UNDEFINED
||
j
==
DF_MISSING
) {
cp
->
type
=
UNDEFINED
;
goto
come_here_if_undefined
;
}
cp
->
type
=
INRANGE
;
/* unless we find out different */
/* EAM Oct 2004 - Substantially rework this section */
/* now that there are many more plot types. */
x
=
y
=
z
=
0.0
;
xtail
=
ytail
=
ztail
=
0.0
;
/* The x, y, z coordinates depend on the mapping type */
switch
(
mapping3d
) {
case
MAP3D_CARTESIAN
:
if
(
j
==
1
) {
x
=
xdatum
;
y
=
ydatum
;
z
=
v
[
0
];
j
=
3
;
break
;
}
if
(
j
==
2
) {
if
(
PM3DSURFACE
!=
this_plot
->
plot_style
)
int_error
(
this_plot
->
token
,
"2 columns only possible with explicit pm3d style (line %d)"
,
df_line_number
);
x
=
xdatum
;
y
=
ydatum
;
z
=
v
[
0
];
color_from_column
(TRUE);
color
=
v
[
1
];
j
=
3
;
break
;
}
/* Assume everybody agrees that x,y,z are the first three specs */
if
(
j
>=
3
) {
x
=
v
[
0
];
y
=
v
[
1
];
z
=
v
[
2
];
break
;
}
break
;
case
MAP3D_SPHERICAL
:
if
(
j
<
2
)
int_error
(
this_plot
->
token
,
"Need 2 or 3 columns"
);
if
(
j
<
3
) {
v
[
2
]
=
1
;
/* default radius */
j
=
3
;
}
/* Convert to radians. */
v
[
0
] *=
ang2rad
;
v
[
1
] *=
ang2rad
;
x
=
v
[
2
]
*
cos
(
v
[
0
])
*
cos
(
v
[
1
]);
y
=
v
[
2
]
*
sin
(
v
[
0
])
*
cos
(
v
[
1
]);
z
=
v
[
2
]
*
sin
(
v
[
1
]);
break
;
case
MAP3D_CYLINDRICAL
:
if
(
j
<
2
)
int_error
(
this_plot
->
token
,
"Need 2 or 3 columns"
);
if
(
j
<
3
) {
v
[
2
]
=
1
;
/* default radius */
j
=
3
;
}
/* Convert to radians. */
v
[
0
] *=
ang2rad
;
x
=
v
[
2
]
*
cos
(
v
[
0
]);
y
=
v
[
2
]
*
sin
(
v
[
0
]);
z
=
v
[
1
];
break
;
default
:
int_error
(
NO_CARET
,
"Internal error: Unknown mapping type"
);
return
;
}
if
(
j
<
df_no_use_specs
)
int_error
(
this_plot
->
token
,
"Wrong number of columns in input data - line %d"
,
df_line_number
);
/* After the first three columns it gets messy because */
/* different plot styles assume different contents in the columns */
if
(
j
>=
4
) {
if
((
this_plot
->
plot_style
==
POINTSTYLE
||
this_plot
->
plot_style
==
LINESPOINTS
)
&&
this_plot
->
lp_properties
.
p_size
==
PTSZ_VARIABLE
) {
cp
->
CRD_PTSIZE
=
v
[
3
];
color
=
z
;
color_from_column
(FALSE);
}
#ifdef
EAM_DATASTRINGS
else
if
(
this_plot
->
plot_style
==
LABELPOINTS
) {
/* 4th column holds label text rather than color */
/* text = df_tokens[3]; */
color
=
z
;
color_from_column
(FALSE);
}
#endif
else
{
color
=
v
[
3
];
color_from_column
(TRUE);
}
}
if
(
j
>=
5
) {
if
((
this_plot
->
plot_style
==
POINTSTYLE
||
this_plot
->
plot_style
==
LINESPOINTS
)
&&
this_plot
->
lp_properties
.
p_size
==
PTSZ_VARIABLE
) {
color
=
v
[
4
];
color_from_column
(TRUE);
}
#ifdef
EAM_DATASTRINGS
if
(
this_plot
->
plot_style
==
LABELPOINTS
) {
/* take color from an explicitly given 5th column */
color
=
v
[
4
];
color_from_column
(TRUE);
}
#endif
}
if
(
j
>=
6
) {
if
(
this_plot
->
plot_style
==
VECTOR
) {
xtail
=
x
+
v
[
3
];
ytail
=
y
+
v
[
4
];
ztail
=
z
+
v
[
5
];
color_from_column
(FALSE);
}
}
#undef
color_from_column
/* Adjust for logscales. Set min/max and point types. Store in cp.
* The macro cannot use continue, as it is wrapped in a loop.
* I regard this as correct goto use
*/
cp
->
type
=
INRANGE
;
STORE_WITH_LOG_AND_UPDATE_RANGE
(
cp
->
x
,
x
,
cp
->
type
,
x_axis
,
NOOP
,
goto
come_here_if_undefined
);
STORE_WITH_LOG_AND_UPDATE_RANGE
(
cp
->
y
,
y
,
cp
->
type
,
y_axis
,
NOOP
,
goto
come_here_if_undefined
);
if
(
this_plot
->
plot_style
==
VECTOR
) {
cptail
->
type
=
INRANGE
;
STORE_WITH_LOG_AND_UPDATE_RANGE
(
cptail
->
x
,
xtail
,
cp
->
type
,
x_axis
,
NOOP
,
goto
come_here_if_undefined
);
STORE_WITH_LOG_AND_UPDATE_RANGE
(
cptail
->
y
,
ytail
,
cp
->
type
,
y_axis
,
NOOP
,
goto
come_here_if_undefined
);
}
if
(
dgrid3d
) {
/* HBB 20010424: in dgrid3d mode, delay log() taking
* and scaling until after the dgrid process. Only for
* z, not for x and y, so we can layout the newly
* created created grid more easily. */
cp
->
z
=
z
;
if
(
this_plot
->
plot_style
==
VECTOR
)
cptail
->
z
=
ztail
;
}
else
{
STORE_WITH_LOG_AND_UPDATE_RANGE
(
cp
->
z
,
z
,
cp
->
type
,
z_axis
,
NOOP
,
goto
come_here_if_undefined
);
if
(
this_plot
->
plot_style
==
VECTOR
)
STORE_WITH_LOG_AND_UPDATE_RANGE
(
cptail
->
z
,
ztail
,
cp
->
type
,
z_axis
,
NOOP
,
goto
come_here_if_undefined
);
if
(
NEED_PALETTE
(
this_plot
)) {
if
(
pm3d_color_from_column
) {
COLOR_STORE_WITH_LOG_AND_UPDATE_RANGE
(
cp
->
CRD_COLOR
,
color
,
cp
->
type
,
COLOR_AXIS
,
NOOP
,
goto
come_here_if_undefined
);
}
else
{
COLOR_STORE_WITH_LOG_AND_UPDATE_RANGE
(
cp
->
CRD_COLOR
,
z
,
cp
->
type
,
COLOR_AXIS
,
NOOP
,
goto
come_here_if_undefined
);
}
}
}
#ifdef
EAM_DATASTRINGS
/* At this point we have stored the point coordinates. Now we need to copy */
/* x,y,z into the text_label structure and add the actual text string. */
if
(
this_plot
->
plot_style
==
LABELPOINTS
)
store_label
(
this_plot
->
labels
,
cp
,
xdatum
,
df_tokens
[
3
],
color
);
#endif
come_here_if_undefined
:
/* some may complain, but I regard this as the correct use of goto */
++
xdatum
;
}
/* end of whileloop - end of surface */
if
(
pm3d_color_from_column
) {
this_plot
->
pm3d_color_from_column
=
pm3d_color_from_column
;
}
if
(
xdatum
>
0
) {
this_plot
->
num_iso_read
++
;
/* Update last iso. */
local_this_iso
->
p_count
=
xdatum
;
/* If this is a VECTOR plot then iso->next is already */
/* occupied by the vector tail coordinates. */
if
(
this_plot
->
plot_style
!=
VECTOR
)
local_this_iso
->
next
=
this_plot
->
iso_crvs
;
this_plot
->
iso_crvs
=
local_this_iso
;
if
(
xdatum
!=
pt_in_iso_crv
)
this_plot
->
has_grid_topology
=
FALSE;
}
else
{
/* Free last allocation */
if
(
this_plot
->
plot_style
==
VECTOR
)
iso_free
(
local_this_iso
->
next
);
iso_free
(
local_this_iso
);
}
/*}}} */
}
if
(
dgrid3d
&&
this_plot
->
num_iso_read
>
0
)
grid_nongrid_data
(
this_plot
);
/* This check used to be done in graph3d */
if
(
X_AXIS
.
min
==
VERYLARGE
||
X_AXIS
.
max
==
-
VERYLARGE
||
Y_AXIS
.
min
==
VERYLARGE
||
Y_AXIS
.
max
==
-
VERYLARGE
||
Z_AXIS
.
min
==
VERYLARGE
||
Z_AXIS
.
max
==
-
VERYLARGE
)
int_warn
(
NO_CARET
,
"Axis range undefined due to improper data values. NaN? Inf?"
);
if
(
this_plot
->
num_iso_read
<=
1
)
this_plot
->
has_grid_topology
=
FALSE;
if
(
this_plot
->
has_grid_topology
&&
!
hidden3d
) {
struct
iso_curve
*
new_icrvs
=
NULL
;
int
num_new_iso
=
this_plot
->
iso_crvs
->
p_count
,
len_new_iso
=
this_plot
->
num_iso_read
;
int
i
;
/* Now we need to set the other direction (pseudo) isolines. */
for
(
i
=
0
;
i
<
num_new_iso
;
i
++
) {
struct
iso_curve
*
new_icrv
=
iso_alloc
(
len_new_iso
);
new_icrv
->
p_count
=
len_new_iso
;
for
(
j
=
0
,
this_iso
=
this_plot
->
iso_crvs
;
this_iso
!=
NULL
;
j
++
,
this_iso
=
this_iso
->
next
) {
/* copy whole point struct to get type too.
* wasteful for windows, with padding */
/* more efficient would be extra pointer to same struct */
new_icrv
->
points
[
j
]
=
this_iso
->
points
[
i
];
}
new_icrv
->
next
=
new_icrvs
;
new_icrvs
=
new_icrv
;
}
/* Append the new iso curves after the read ones. */
for
(
this_iso
=
this_plot
->
iso_crvs
;
this_iso
->
next
!=
NULL
;
this_iso
=
this_iso
->
next
);
this_iso
->
next
=
new_icrvs
;
}
}
static
void
print_3dtable
(
int
pcount
)
{
struct
surface_points
*
this_plot
;
int
i
,
surface
;
struct
coordinate
GPHUGE
*
point
;
char
*
buffer
=
gp_alloc
(
150
,
"print_3dtable output buffer"
);
FILE
*
outfile
=
(
table_outfile
) ?
table_outfile
:
gpoutfile
;
for
(
surface
=
0
,
this_plot
=
first_3dplot
;
surface
<
pcount
;
this_plot
=
this_plot
->
next_sp
,
surface
++
) {
fprintf
(
outfile
,
"\n#Surface %d of %d surfaces\n"
,
surface
,
pcount
);
if
(
draw_surface
) {
struct
iso_curve
*
icrvs
;
int
curve
;
/* only the curves in one direction */
for
(
curve
=
0
,
icrvs
=
this_plot
->
iso_crvs
;
icrvs
&&
curve
<
this_plot
->
num_iso_read
;
icrvs
=
icrvs
->
next
,
curve
++
) {
fprintf
(
outfile
,
"\n#IsoCurve %d, %d points\n#x y z type\n"
,
curve
,
icrvs
->
p_count
);
for
(
i
=
0
,
point
=
icrvs
->
points
;
i
<
icrvs
->
p_count
;
i
++
,
point
++
) {
/* HBB 20020405: new macro to use the 'set format'
* in their full flexibility */
#define
OUTPUT_NUMBER
(
field
,
axis
) \
gprintf(buffer, 150, axis_array[axis].formatstring, \
1.0, point->field); \
fputs(buffer, outfile); \
fputc(' ', outfile);
OUTPUT_NUMBER
(
x
,
FIRST_X_AXIS
);
OUTPUT_NUMBER
(
y
,
FIRST_Y_AXIS
);
OUTPUT_NUMBER
(
z
,
FIRST_Z_AXIS
);
fprintf
(
outfile
,
"%c\n"
,
point
->
type
==
INRANGE
?
'i'
:
point
->
type
==
OUTRANGE
?
'o'
:
'u'
);
}
/* for(point) */
}
/* for(icrvs) */
putc
(
'\n'
,
outfile
);
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL