Skip to content
Snippets Groups Projects
Commit cd593bcd authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

add map output

parent 389e18eb
Branches
No related tags found
No related merge requests found
......@@ -36,33 +36,24 @@ var inputs = {
mesh:{type:'STL',
event:function(evt){
mod.mesh = new DataView(evt.detail)
find_limits_map()}},
settings:{type:'',
event:function(evt){
for (var p in evt.detail)
;
find_limits_map()}}}
//
// outputs
//
var outputs = {
map:{type:'F32',label:'height map',
event:function(){
}},
image:{type:'RGBA',
event:function(){
var ctx = mod.img.getContext("2d")
var img = ctx.getImageData(0,0,mod.img.width,mod.img.height)
mods.output(mod,'image',img)
}},
imageInfo:{type:'',
event:function(){
map:{type:'',label:'height map',
event:function(heightmap){
var obj = {}
obj.name = "mesh height map"
obj.map = heightmap
obj.xmin = mod.xmin
obj.xmax = mod.xmax
obj.ymin = mod.ymin
obj.ymax = mod.ymax
obj.zmin = mod.zmin
obj.zmax = mod.zmax
obj.width = mod.img.width
obj.height = mod.img.height
obj.dpi = mod.img.width/(mod.dx*parseFloat(mod.inunits.value))
mods.output(mod,'imageInfo',obj)
mods.output(mod,'map',heightmap)
}}}
//
// interface
......@@ -312,6 +303,7 @@ function map_mesh() {
var h = mod.img.height
var w = mod.img.width
var buf = new Uint8ClampedArray(evt.data.imgbuffer)
var map = new Float32Array(evt.data.mapbuffer)
var imgdata = new ImageData(buf,w,h)
var ctx = mod.img.getContext("2d")
ctx.putImageData(imgdata,0,0)
......@@ -330,8 +322,7 @@ function map_mesh() {
var ctx = mod.mapcanvas.getContext("2d")
ctx.clearRect(0,0,mod.mapcanvas.width,mod.mapcanvas.height)
ctx.drawImage(mod.img,x0,y0,wd,hd)
outputs.image.event()
outputs.imageInfo.event()
outputs.map.event(map)
})
var ctx = mod.mapcanvas.getContext("2d")
ctx.clearRect(0,0,mod.mapcanvas.width,mod.mapcanvas.height)
......@@ -339,15 +330,16 @@ function map_mesh() {
mod.img.height = Math.round(mod.img.width*mod.dy/mod.dx)
var ctx = mod.img.getContext("2d")
var img = ctx.getImageData(0,0,mod.img.width,mod.img.height)
var map = new Float32Array(1000)
var map = new Float32Array(mod.img.width*mod.img.height)
webworker.postMessage({
height:mod.img.height,width:mod.img.width,
imgbuffer:img.data.buffer,
mapbuffer:map.buffer,
mesh:mod.mesh,
xmin:mod.xmin,xmax:mod.xmax,
ymin:mod.ymin,ymax:mod.ymax,
zmin:mod.zmin,zmax:mod.zmax},
[img.data.buffer])
[img.data.buffer,map.buffer])
}
function map_worker() {
self.addEventListener('message',function(evt) {
......@@ -361,7 +353,7 @@ function map_worker() {
var zmin = evt.data.zmin
var zmax = evt.data.zmax
var buf = new Uint8ClampedArray(evt.data.imgbuffer)
var map = new Float32Array(h*w)
var map = new Float32Array(evt.data.mapbuffer)
//
// get vars from buffer
//
......@@ -518,7 +510,7 @@ function map_worker() {
//
// output the map
//
self.postMessage({imgbuffer:buf.buffer},[buf.buffer])
self.postMessage({imgbuffer:buf.buffer,mapbuffer:map.buffer},[buf.buffer,map.buffer])
self.close()
})
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment