Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pub
mods
Commits
237096a8
Commit
237096a8
authored
Jan 21, 2020
by
Neil Gershenfeld
Browse files
to worker
parent
8fdcd854
Changes
1
Hide whitespace changes
Inline
Side-by-side
modules/processes/mill/raster/3D
View file @
237096a8
...
...
@@ -212,82 +212,114 @@ var interface = function(div){
//
// local functions
//
// calculate
_
path
// calculate
path
//
function calculate_path() {
var h = mod.height
var w = mod.width
var xmin = mod.xmin
var xmax = mod.xmax
var ymin = mod.ymin
var ymax = mod.ymax
var zmin = mod.zmin
var zmax = mod.zmax
//
// clear SVG
//
var svg = document.getElementById(mod.div.id+'svg')
svg.setAttribute('viewBox',"0 0 "+(w-1)+" "+(h-1))
var g = document.getElementById(mod.div.id+'g')
svg.removeChild(g)
var g = document.createElementNS('http://www.w3.org/2000/svg','g')
g.setAttribute('id',mod.div.id+'g')
svg.appendChild(g)
//
// line loop
//
var ix = 0
var iy = h-1
var dx = 1
var dy = 0
var x = xmin+(xmax-xmin)*ix/(w-1)
var y = ymin+(ymax-ymin)*iy/(h-1)
var z = mod.map[(h-1-iy)*w+ix]
var dz = 0.1*h*(zmax-z)/(ymax-ymin)
while (1) {
var ixp = ix
var iyp = iy
var dzp = dz
ix += dx
iy += dy
if (iy <= 0)
break;
var x = xmin+(xmax-xmin)*ix/(w-1)
var y = ymin+(ymax-ymin)*iy/(h-1)
var z = mod.map[iy*w+ix]
var dz = 0.1*h*(zmax-z)/(zmax-zmin)
var line = document.createElementNS('http://www.w3.org/2000/svg','line')
line.setAttribute('stroke','black')
line.setAttribute('stroke-width',1)
line.setAttribute('stroke-linecap','round')
line.setAttribute('x1',ixp)
line.setAttribute('y1',iyp+dzp)
line.setAttribute('x2',ix)
line.setAttribute('y2',iy+dz)
g.appendChild(line)
if (ix == (mod.width-1)) {
if (dx == 1) {
dx = 0
dy = -10
var blob = new Blob(['('+calculate_path_worker.toString()+'())'])
var url = window.URL.createObjectURL(blob)
var webworker = new Worker(url)
webworker.addEventListener('message',function(evt) {
mod.triangles = evt.data.triangles
mod.path = evt.data.path
mod.label.nodeValue = 'calculate'
mod.labelspan.style.fontWeight = 'normal'
//
// clear SVG
//
var svg = document.getElementById(mod.div.id+'svg')
svg.setAttribute('viewBox',"0 0 "+(mod.width-1)+" "+(mod.height-1))
var g = document.getElementById(mod.div.id+'g')
svg.removeChild(g)
var g = document.createElementNS('http://www.w3.org/2000/svg','g')
g.setAttribute('id',mod.div.id+'g')
svg.appendChild(g)
//
// plot path
//
for (var i = 1; i < mod.path[0].length; ++i) {
var ixp = mod.path[0][i-1][0]
var iyp = mod.path[0][i-1][1]
var izp = 0.1*mod.path[0][i-1][2]
var ix = mod.path[0][i][0]
var iy = mod.path[0][i][1]
var iz = 0.1*mod.path[0][i][2]
var line = document.createElementNS('http://www.w3.org/2000/svg','line')
line.setAttribute('stroke','black')
line.setAttribute('stroke-width',1)
line.setAttribute('stroke-linecap','round')
line.setAttribute('x1',ixp)
line.setAttribute('y1',iyp-izp)
line.setAttribute('x2',ix)
line.setAttribute('y2',iy-iz)
g.appendChild(line)
}
else {
dx = -1
dy = 0
}
}
else if (ix == 0) {
if (dx == -1) {
dx = 0
dy = -10
})
webworker.postMessage({
h:mod.height,w:mod.width,
xmin:mod.xmin,xmax:mod.xmax,
ymin:mod.ymin,ymax:mod.ymax,
zmin:mod.zmin,zmax:mod.zmax,
map:mod.map})
}
//
// calculate path worker
//
function calculate_path_worker() {
self.addEventListener('message',function(evt) {
var h = evt.data.h
var w = evt.data.w
var xmin = evt.data.xmin
var xmax = evt.data.xmax
var ymin = evt.data.ymin
var ymax = evt.data.ymax
var zmin = evt.data.zmin
var zmax = evt.data.zmax
var map = evt.data.map
var path = [[]]
//
// line loop
//
var ix = 0
var iy = h-1
var dx = 1
var dy = 0
var iz = Math.floor((map[iy*w+ix]-zmax)*w/(xmax-xmin))
while (1) {
var ixp = ix
var iyp = iy
ix += dx
iy += dy
if (iy <= 0)
break;
var iz = Math.floor((map[iy*w+ix]-zmax)*w/(xmax-xmin))
path[0].push([ix,iy,iz])
if (ix == (w-1)) {
if (dx == 1) {
dx = 0
dy = -10
}
else {
dx = -1
dy = 0
}
}
else {
dx = 1
dy = 0
else if (ix == 0) {
if (dx == -1) {
dx = 0
dy = -10
}
else {
dx = 1
dy = 0
}
}
}
}
mod.label.nodeValue = 'calculate'
mod.labelspan.style.fontWeight = 'normal'
//
// return
//
self.postMessage({path:path})
self.close()
})
}
//
// return values
...
...
Write
Preview
Supports
Markdown
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