Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
bf873288
Commit
bf873288
authored
Sep 04, 2011
by
Kliment Yanev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add zscaper module to convert images to heightmaps
parent
d2b90ebe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
zscaper.py
zscaper.py
+80
-0
No files found.
zscaper.py
0 → 100644
View file @
bf873288
import
stltool
,
wx
,
math
a
=
wx
.
App
()
def
cross
(
v1
,
v2
):
return
[
v1
[
1
]
*
v2
[
2
]
-
v1
[
2
]
*
v2
[
1
],
v1
[
0
]
*
v2
[
2
]
-
v1
[
2
]
*
v2
[
0
],
v1
[
0
]
*
v2
[
1
]
-
v1
[
1
]
*
v2
[
0
]]
def
genfacet
(
v
):
veca
=
[
v
[
1
][
0
]
-
v
[
0
][
0
],
v
[
1
][
1
]
-
v
[
0
][
1
],
v
[
1
][
2
]
-
v
[
0
][
2
]]
vecb
=
[
v
[
2
][
0
]
-
v
[
0
][
0
],
v
[
2
][
1
]
-
v
[
0
][
1
],
v
[
2
][
2
]
-
v
[
0
][
2
]]
vecx
=
cross
(
veca
,
vecb
)
vlen
=
math
.
sqrt
(
sum
(
map
(
lambda
x
:
x
*
x
,
vecx
)))
normal
=
map
(
lambda
x
:
x
/
vlen
,
vecx
)
return
[
normal
,
v
]
def
genscape
(
data
=
[[
0
,
1
,
0
,
0
],[
1
,
0
,
2
,
0
],[
1
,
0
,
0
,
0
],[
0
,
1
,
0
,
1
]],
pscale
=
1.0
,
bheight
=
1.0
,
zscale
=
1.0
):
o
=
stltool
.
stl
(
None
)
datal
=
len
(
data
)
datah
=
len
(
data
[
0
])
#create bottom:
bmidpoint
=
(
pscale
*
(
datal
-
1
)
/
2.0
,
pscale
*
(
datah
-
1
)
/
2.0
)
#print range(datal),bmidpoint
for
i
in
zip
(
range
(
datal
+
1
)[:
-
1
],
range
(
datal
+
1
)[
1
:])[:
-
1
]:
#print (pscale*i[0],pscale*i[1])
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
]]]]
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
]]]]
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
]])]
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
]])]
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
]])]
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
]])]
#print o.facets[-1]
pass
#print o.facets[-4:]
for
i
in
zip
(
range
(
datah
+
1
)[:
-
1
],
range
(
datah
+
1
)[
1
:])[:
-
1
]:
#print (pscale*i[0],pscale*i[1])
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
]]]]
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
]]]]
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
]])]
#break
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
]])]
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
]])]
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
]])]
pass
for
i
in
xrange
(
datah
-
1
):
for
j
in
xrange
(
datal
-
1
):
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
]])]
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
]])]
#print o.facets[-1]
facet
=
[[
0
,
0
,
0
],[[
0
,
0
,
0
],[
0
,
0
,
0
],[
0
,
0
,
0
]]]
return
o
def
zimage
(
name
,
out
):
i
=
wx
.
Image
(
name
)
s
=
i
.
GetSize
()
print
len
(
map
(
ord
,
i
.
GetData
()[::
3
]))
b
=
map
(
ord
,
i
.
GetData
()[::
3
])
data
=
[]
for
i
in
xrange
(
s
[
0
]):
data
+=
[
b
[
i
*
s
[
1
]:(
i
+
1
)
*
s
[
1
]]]
data
=
[
i
[::
5
]
for
i
in
data
[::
5
]]
stltool
.
emitstl
(
out
,
genscape
(
data
,
zscale
=
0.1
)
.
facets
,
name
)
"""
class scapewin(wx.Frame):
def __init__(self,size=(400,530)):
wx.Frame.__init__(self,None,title="Right-click to load an image",size=size)
self.SetIcon(wx.Icon("plater.ico",wx.BITMAP_TYPE_ICO))
self.SetClientSize(size)
self.panel=wx.Panel(self,size=size)
"""
if
__name__
==
'__main__'
:
"""
app = wx.App(False)
main = scapewin()
main.Show()
app.MainLoop()
"""
zimage
(
"testimg.png"
,
"testobj.stl"
)
del
a
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment