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

add map output

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