Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mods
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
mods
Commits
237096a8
Commit
237096a8
authored
Jan 21, 2020
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
to worker
parent
8fdcd854
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/processes/mill/raster/3D
+102
-70
102 additions, 70 deletions
modules/processes/mill/raster/3D
with
102 additions
and
70 deletions
modules/processes/mill/raster/3D
+
102
−
70
View file @
237096a8
...
@@ -212,60 +212,88 @@ var interface = function(div){
...
@@ -212,60 +212,88 @@ var interface = function(div){
//
//
// local functions
// local functions
//
//
// calculate
_
path
// calculate
path
//
//
function calculate_path() {
function calculate_path() {
var
h = mod.height
var
blob = new Blob(['('+calculate_path_worker.toString()+'())'])
var
w = mod.width
var
url = window.URL.createObjectURL(blob)
var
xmin = mod.xmin
var
webworker = new Worker(url)
var xmax = mod.xmax
webworker.addEventListener('message',function(evt) {
var ymin = mod.ymin
mod.triangles = evt.data.triangles
var ymax = mod.ymax
mod.path = evt.data.path
var zmin = mod.zmin
mod.label.nodeValue = 'calculate'
var zmax = mod.zmax
mod.labelspan.style.fontWeight = 'normal'
//
//
// clear SVG
// clear SVG
//
//
var svg = document.getElementById(mod.div.id+'svg')
var svg = document.getElementById(mod.div.id+'svg')
svg.setAttribute('viewBox',"0 0 "+(
w-1)+" "+(h
-1))
svg.setAttribute('viewBox',"0 0 "+(
mod.width-1)+" "+(mod.height
-1))
var g = document.getElementById(mod.div.id+'g')
var g = document.getElementById(mod.div.id+'g')
svg.removeChild(g)
svg.removeChild(g)
var g = document.createElementNS('http://www.w3.org/2000/svg','g')
var g = document.createElementNS('http://www.w3.org/2000/svg','g')
g.setAttribute('id',mod.div.id+'g')
g.setAttribute('id',mod.div.id+'g')
svg.appendChild(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)
}
})
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
// line loop
//
//
var ix = 0
var ix = 0
var iy = h-1
var iy = h-1
var dx = 1
var dx = 1
var dy = 0
var dy = 0
var x = xmin+(xmax-xmin)*ix/(w-1)
var iz = Math.floor((map[iy*w+ix]-zmax)*w/(xmax-xmin))
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) {
while (1) {
var ixp = ix
var ixp = ix
var iyp = iy
var iyp = iy
var dzp = dz
ix += dx
ix += dx
iy += dy
iy += dy
if (iy <= 0)
if (iy <= 0)
break;
break;
var x = xmin+(xmax-xmin)*ix/(w-1)
var iz = Math.floor((map[iy*w+ix]-zmax)*w/(xmax-xmin))
var y = ymin+(ymax-ymin)*iy/(h-1)
path[0].push([ix,iy,iz])
var z = mod.map[iy*w+ix]
if (ix == (w-1)) {
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) {
if (dx == 1) {
dx = 0
dx = 0
dy = -10
dy = -10
...
@@ -286,8 +314,12 @@ function calculate_path() {
...
@@ -286,8 +314,12 @@ function calculate_path() {
}
}
}
}
}
}
mod.label.nodeValue = 'calculate'
//
mod.labelspan.style.fontWeight = 'normal'
// return
//
self.postMessage({path:path})
self.close()
})
}
}
//
//
// return values
// return values
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment