Debian Codegraph @

sys/Graphics_surface.cpp

raw symbols SCIP
1 /* Graphics_surface.cpp
2 *
3 * Copyright (C) 1992-2005,2008,2011,2016-2019 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/
20
21 void Graphics_surfacecxx . . $ Graphics_surface(7fed75d2e80ca61a). (Graphicscxx . . $ Graphics# me, constMATVUcxx . . $ constMATVU# const& z,
22 double x1, double x2, double y1, double y2,
23 double minimum, double maximum,
24 double /* elevation */, double /* azimuth */)
25 {
26 /*
27 `sum` is the running sum of the x and y indices of the back corner of each tetragon.
28 The x and y indices of the back corner of the backmost tetragon are z.ncol and z.nrow,
29 and the x and y indices of the front corner of the frontmost tetragon are 1 and 1,
30 so that the x and y indices of its back corner are 1 + 1 and 1 + 1.
31 */
32 integercxx . . $ integer# const maxsum = z.ncolcxx . . $ constmatrixview#ncol. + z.nrowcxx . . $ constmatrixview#nrow., minsum = (1 + 1) + (1 + 1);
33 if (z.ncolcxx . . $ constmatrixview#ncol. <= 1 || z.nrowcxx . . $ constmatrixview#nrow. <= 1) return;
34 double const dx = (x2 - x1) / (z.ncolcxx . . $ constmatrixview#ncol. - 1);
35 double const dy = (y2 - y1) / (z.nrowcxx . . $ constmatrixview#nrow. - 1);
36
37 /*
38 We start at the back of the surface plot.
39 This part of the picture may be overdrawn by points more forward.
40 */
41 for (integercxx . . $ integer# sum = maxsum; sum >= minsum; sum --) {
42
43 /*
44 We are going to cycle over a diagonal sequence of points.
45 Compute the row boundaries of this sequence.
46 */
47 integercxx . . $ integer# iymin = 1 + 1, iymax = z.nrowcxx . . $ constmatrixview#nrow.;
48 if (iymin < sum - z.nrowcxx . . $ constmatrixview#nrow.) iymin = sum - z.nrowcxx . . $ constmatrixview#nrow.;
49 if (iymax > sum - (1 + 1)) iymax = sum - (1 + 1);
50 for (integercxx . . $ integer# iy = iymin; iy <= iymax; iy ++) {
51
52 /*
53 Compute the indices of all four points.
54 */
55 integercxx . . $ integer# const ix = sum - iy;
56 integercxx . . $ integer# const ixback = ix, ixfront = ix - 1, ixleft = ix - 1, ixright = ix;
57 integercxx . . $ integer# const iyback = iy, iyfront = iy - 1, iyleft = iy, iyright = iy - 1;
58
59 /*
60 Compute the world coordinates of all four points.
61 */
62 double const xback = x1 + (ixback - 1) * dx, xright = xback;
63 double const xfront = x1 + (ixfront - 1) * dx, xleft = xfront;
64 double const yback = y1 + (iyback - 1) * dy, yleft = yback;
65 double const yfront = y1 + (iyfront - 1) * dy, yright = yfront;
66 double const zback = z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).iyback] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).ixback], zfront = z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).iyfront] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).ixfront];
67 double const zleft = z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).iyleft] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).ixleft], zright = z [cxx . . $ constmatrixview#`operator[]`(7a6174ed67b49158).iyright] [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).ixright];
68
69 /*
70 The Graphics library uses a two-dimensional world, so we have to convert
71 to 2-D world coordinates, which we call x [0..3] and y [0..3].
72 We suppose that world coordinate `x` = 0 is in the centre of the figure,
73 and that the left and right borders of the figure have world coordinates -1.0 and +1.0.
74 Also, we suppose that the bottom and top are around `minimum` and `maximum`.
75 */
76 double x [5], y [5];
77
78 /*
79 BUG: elevation and azimuth are fixed.
80 */
81 double const up = 0.3 * (maximum - minimum), xscale = 1.0 / (x2 - x1), yscale = 1.0 / (y2 - y1);
82
83 /*
84 The back point.
85 */
86 x [0] = (xback - x1) * xscale - (yback - y1) * yscale;
87 y [0] = up * ((xback - x1) * xscale + (yback - y1) * yscale) + zback;
88
89 /*
90 The right point.
91 */
92 x [1] = (xright - x1) * xscale - (yright - y1) * yscale;
93 y [1] = up * ((xright - x1) * xscale + (yright - y1) * yscale) + zright;
94
95 /*
96 The front point.
97 */
98 x [2] = (xfront - x1) * xscale - (yfront - y1) * yscale;
99 y [2] = up * ((xfront - x1) * xscale + (yfront - y1) * yscale) + zfront;
100
101 /*
102 The left point.
103 */
104 x [3] = (xleft - x1) * xscale - (yleft - y1) * yscale;
105 y [3] = up * ((xleft - x1) * xscale + (yleft - y1) * yscale) + zleft;
106
107 /*
108 Paint the tetragon in the average grey value, white at the top.
109 This gives the idea of height.
110 */
111 Graphics_setGreycxx . . $ Graphics_setGrey(2514a1c07b6be5e2). (me, (0.25 * (zback + zright + zfront + zleft) - minimum) / (maximum - minimum));
112 Graphics_fillAreacxx . . $ Graphics_fillArea(23a712ce109b96e0). (me, 4, & x [0], & y [0]);
113
114 /*
115 Draw the borders of the tetragon in black.
116 This gives the idea of steepness and viewing angle.
117 */
118 Graphics_setGreycxx . . $ Graphics_setGrey(2514a1c07b6be5e2). (me, 0.0);
119 x [4] = x [0]; // close polygon
120 y [4] = y [0]; // close polygon
121 Graphics_polylinecxx . . $ Graphics_polyline(23a712ce109b96e0). (me, 5, & x [0], & y [0]);
122 }
123 }
124 }
125
126 /* End of file Graphics_surface.cpp */