12 # |
12 # |
13 # You should have received a copy of the GNU General Public License |
13 # You should have received a copy of the GNU General Public License |
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>. |
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>. |
15 |
15 |
16 import wx |
16 import wx |
17 from stltool import stl, genfacet, emitstl |
17 from .stltool import stl, genfacet, emitstl |
18 a = wx.App() |
18 a = wx.App() |
19 |
19 |
20 def genscape(data = [[0, 1, 0, 0], [1, 0, 2, 0], [1, 0, 0, 0], [0, 1, 0, 1]], |
20 def genscape(data = [[0, 1, 0, 0], [1, 0, 2, 0], [1, 0, 0, 0], [0, 1, 0, 1]], |
21 pscale = 1.0, bheight = 1.0, zscale = 1.0): |
21 pscale = 1.0, bheight = 1.0, zscale = 1.0): |
22 o = stl(None) |
22 o = stl(None) |
23 datal = len(data) |
23 datal = len(data) |
24 datah = len(data[0]) |
24 datah = len(data[0]) |
25 # create bottom: |
25 # create bottom: |
26 bmidpoint = (pscale * (datal - 1) / 2.0, pscale * (datah - 1) / 2.0) |
26 bmidpoint = (pscale * (datal - 1) / 2.0, pscale * (datah - 1) / 2.0) |
27 # print range(datal), bmidpoint |
27 # print range(datal), bmidpoint |
28 for i in zip(range(datal + 1)[:-1], range(datal + 1)[1:])[:-1]: |
28 for i in list(zip(range(datal + 1)[:-1], range(datal + 1)[1:]))[:-1]: |
29 # print (pscale*i[0], pscale*i[1]) |
29 # print (pscale*i[0], pscale*i[1]) |
30 o.facets += [[[0, 0, -1], [[0.0, pscale * i[0], 0.0], [0.0, pscale * i[1], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
30 o.facets += [[[0, 0, -1], [[0.0, pscale * i[0], 0.0], [0.0, pscale * i[1], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
31 o.facets += [[[0, 0, -1], [[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
31 o.facets += [[[0, 0, -1], [[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
32 o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], data[i[1]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0]])] |
32 o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], data[i[1]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0]])] |
33 o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], data[i[1]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[1], 0.0]])] |
33 o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], data[i[1]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[1], 0.0]])] |
34 o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0], [0.0, pscale * i[0], 0.0]])] |
34 o.facets += [genfacet([[0.0, pscale * i[0], data[i[0]][0] * zscale + bheight], [0.0, pscale * i[1], 0.0], [0.0, pscale * i[0], 0.0]])] |
35 o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], 0.0]])] |
35 o.facets += [genfacet([[2.0 * bmidpoint[1], pscale * i[1], 0.0], [2.0 * bmidpoint[1], pscale * i[0], data[i[0]][datah - 1] * zscale + bheight], [2.0 * bmidpoint[1], pscale * i[0], 0.0]])] |
36 for i in zip(range(datah + 1)[: - 1], range(datah + 1)[1:])[: - 1]: |
36 for i in list(zip(range(datah + 1)[: - 1], range(datah + 1)[1:]))[: - 1]: |
37 # print (pscale * i[0], pscale * i[1]) |
37 # print (pscale * i[0], pscale * i[1]) |
38 o.facets += [[[0, 0, -1], [[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
38 o.facets += [[[0, 0, -1], [[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
39 o.facets += [[[0, 0, -1], [[pscale * i[0], 2.0 * bmidpoint[0], 0.0], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
39 o.facets += [[[0, 0, -1], [[pscale * i[0], 2.0 * bmidpoint[0], 0.0], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [bmidpoint[0], bmidpoint[1], 0.0]]]] |
40 o.facets += [genfacet([[pscale * i[1], 0.0, data[0][i[1]] * zscale + bheight], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[1], 0.0, 0.0]])] |
40 o.facets += [genfacet([[pscale * i[1], 0.0, data[0][i[1]] * zscale + bheight], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[1], 0.0, 0.0]])] |
41 o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], data[datal - 1][i[1]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0]])] |
41 o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], data[datal - 1][i[1]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0]])] |
42 o.facets += [genfacet([[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[0], 0.0, 0.0]])] |
42 o.facets += [genfacet([[pscale * i[1], 0.0, 0.0], [pscale * i[0], 0.0, data[0][i[0]] * zscale + bheight], [pscale * i[0], 0.0, 0.0]])] |
43 o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [pscale * i[0], 2.0 * bmidpoint[0], 0.0]])] |
43 o.facets += [genfacet([[pscale * i[0], 2.0 * bmidpoint[0], data[datal - 1][i[0]] * zscale + bheight], [pscale * i[1], 2.0 * bmidpoint[0], 0.0], [pscale * i[0], 2.0 * bmidpoint[0], 0.0]])] |
44 for i in xrange(datah - 1): |
44 for i in range(datah - 1): |
45 for j in xrange(datal - 1): |
45 for j in range(datal - 1): |
46 o.facets += [genfacet([[pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j), data[j][i + 1] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])] |
46 o.facets += [genfacet([[pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j), data[j][i + 1] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])] |
47 o.facets += [genfacet([[pscale * (i), pscale * (j + 1), data[j + 1][i] * zscale + bheight], [pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])] |
47 o.facets += [genfacet([[pscale * (i), pscale * (j + 1), data[j + 1][i] * zscale + bheight], [pscale * i, pscale * j, data[j][i] * zscale + bheight], [pscale * (i + 1), pscale * (j + 1), data[j + 1][i + 1] * zscale + bheight]])] |
48 # print o.facets[-1] |
48 # print o.facets[-1] |
49 return o |
49 return o |
50 def zimage(name, out): |
50 def zimage(name, out): |
51 i = wx.Image(name) |
51 i = wx.Image(name) |
52 s = i.GetSize() |
52 s = i.GetSize() |
53 print len(map(ord, i.GetData()[::3])) |
53 b = list(map(ord, i.GetData()[::3])) |
54 b = map(ord, i.GetData()[::3]) |
54 print(b) |
55 data = [] |
55 data = [] |
56 for i in xrange(s[0]): |
56 for i in range(s[0]): |
57 data += [b[i * s[1]:(i + 1) * s[1]]] |
57 data += [b[i * s[1]:(i + 1) * s[1]]] |
58 # data = [i[::5] for i in data[::5]] |
58 # data = [i[::5] for i in data[::5]] |
59 emitstl(out, genscape(data, zscale = 0.1).facets, name) |
59 emitstl(out, genscape(data, zscale = 0.1).facets, name) |
60 |
60 |
61 """ |
61 """ |