Thu, 07 Jul 2016 11:58:38 +0200
svg crowbar fixes
15 | 1 | # This file is part of the Printrun suite. |
2 | # | |
3 | # Printrun is free software: you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation, either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # Printrun is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
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/>. | |
15 | ||
16 | import wx | |
17 | from stltool import stl, genfacet, emitstl | |
18 | a = wx.App() | |
19 | ||
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): | |
22 | o = stl(None) | |
23 | datal = len(data) | |
24 | datah = len(data[0]) | |
25 | # create bottom: | |
26 | bmidpoint = (pscale * (datal - 1) / 2.0, pscale * (datah - 1) / 2.0) | |
27 | # print range(datal), bmidpoint | |
28 | for i in zip(range(datal + 1)[:-1], range(datal + 1)[1:])[:-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]]]] | |
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]])] | |
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]])] | |
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]: | |
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]]]] | |
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]])] | |
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]])] | |
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): | |
45 | for j in xrange(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]])] | |
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] | |
49 | return o | |
50 | def zimage(name, out): | |
51 | i = wx.Image(name) | |
52 | s = i.GetSize() | |
53 | print len(map(ord, i.GetData()[::3])) | |
54 | b = map(ord, i.GetData()[::3]) | |
55 | data = [] | |
56 | for i in xrange(s[0]): | |
57 | data += [b[i * s[1]:(i + 1) * s[1]]] | |
58 | # data = [i[::5] for i in data[::5]] | |
59 | emitstl(out, genscape(data, zscale = 0.1).facets, name) | |
60 | ||
61 | """ | |
62 | class scapewin(wx.Frame): | |
63 | def __init__(self, size = (400, 530)): | |
64 | wx.Frame.__init__(self, None, | |
65 | title = "Right-click to load an image", size = size) | |
66 | self.SetIcon(wx.Icon("plater.png", wx.BITMAP_TYPE_PNG)) | |
67 | self.SetClientSize(size) | |
68 | self.panel = wx.Panel(self, size = size) | |
69 | ||
70 | ||
71 | """ | |
72 | if __name__ == '__main__': | |
73 | """ | |
74 | app = wx.App(False) | |
75 | main = scapewin() | |
76 | main.Show() | |
77 | app.MainLoop() | |
78 | """ | |
79 | zimage("catposthtmap2.jpg", "testobj.stl") | |
80 | del a |