printrun-src/printrun/zscaper.py

Fri, 03 Jun 2016 10:06:09 +0200

author
mbayer
date
Fri, 03 Jun 2016 10:06:09 +0200
changeset 18
11f6d97f83b0
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

forgot svg preamble & postamble

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

mercurial