forked from neurolabusc/niivue-onnx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9de1aa5
commit 00fd8b0
Showing
7 changed files
with
231 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
self.addEventListener('message', function(e) { | ||
const file = e.data.blob | ||
const percentage = e.data.percentage || 0.5 | ||
const simplify_name = e.data.simplify_name | ||
const isoValue = e.data.isoValue || NaN | ||
onlyLargest = e.data.onlyLargest || false | ||
fillBubbles = e.data.fillBubbles || false | ||
postSmooth = e.data.postSmooth || 0 | ||
verbose = e.data.berbose || true | ||
prepare_and_simplify(file, percentage, simplify_name, isoValue, onlyLargest, fillBubbles, postSmooth, verbose) | ||
}, false) | ||
|
||
var Module = { | ||
'print': function(text) { | ||
console.log(text) | ||
self.postMessage({"log":text}) | ||
} | ||
} | ||
|
||
self.importScripts("nii2mesh.js?rnd="+Math.random()) | ||
|
||
let last_file_name = undefined | ||
|
||
function prepare_and_simplify(file, percentage, simplify_name, isoValue = 1, onlyLargest = false, fillBubbles = false , postSmooth = 0, verbose = true) { | ||
var filename = file.name | ||
// if simplify on the same file, don't even read the file | ||
if (filename === last_file_name) { | ||
console.log("skipping load and create data file") | ||
simplify(filename, percentage, simplify_name, isoValue, onlyLargest, fillBubbles, postSmooth, verbose) | ||
return | ||
} else { // remove last file in memory | ||
if (last_file_name !== undefined) | ||
Module.FS_unlink(last_file_name) | ||
} | ||
last_file_name = filename | ||
var fr = new FileReader() | ||
fr.readAsArrayBuffer(file) | ||
fr. onloadend = function (e) { | ||
var data = new Uint8Array(fr.result) | ||
Module.FS_createDataFile(".", filename, data, true, true) | ||
simplify(filename, percentage, simplify_name, isoValue, onlyLargest, fillBubbles, postSmooth, verbose) | ||
} | ||
} | ||
|
||
function simplify(filename, percentage, simplify_name, isoValue = 1, onlyLargest = false, fillBubbles = false , postSmooth = 0, verbose = true) { | ||
Module.ccall("simplify", // c function name | ||
undefined, // return | ||
["string", "number", "string", "number","boolean","boolean","number","boolean"], // param | ||
[filename, percentage, simplify_name, isoValue, onlyLargest, fillBubbles,postSmooth, verbose] | ||
) | ||
let out_bin = Module.FS_readFile(simplify_name) | ||
// sla should work for binary mz3 | ||
let file = new Blob([out_bin], {type: 'application/sla'}) | ||
self.postMessage({"blob":file}) | ||
} |