Skip to content

Commit

Permalink
add support for odt
Browse files Browse the repository at this point in the history
  • Loading branch information
hanayik committed Dec 20, 2024
1 parent a93d10a commit 3f8d03e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
30 changes: 16 additions & 14 deletions js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,27 @@ <h1>Niimath WASM Demo</h1>
const t0 = performance.now();

// test the -mesh command and mesh output
const outName = 'out.mz3';
const outFile = await niimath.image(selectedFile)
.mesh({
i: 'm', // 'm' for medium
b: 1, // fill bubbles
v: 0 // not verbose
})
.run(outName)
const t1 = performance.now();
console.log("niimath wasm took " + (t1 - t0) + " milliseconds.")

// test with a volume output
// const outName = 'out.nii.gz';
// const outName = 'out.mz3';
// const outFile = await niimath.image(selectedFile)
// .sobel()
// .mesh({
// i: 'm', // 'm' for medium
// b: 1, // fill bubbles
// v: 0 // not verbose
// })
// .run(outName)
// const t1 = performance.now();
// console.log("niimath wasm took " + (t1 - t0) + " milliseconds.")

// test with a volume output
const outName = 'out.nii.gz';
niimath.setOutputDataType('input')
const outFile = await niimath.image(selectedFile)
.sobel()
.run(outName)
console.log(niimath.outputDataType)
const t1 = performance.now();
console.log("niimath wasm took " + (t1 - t0) + " milliseconds.")

// Create a download link for the processed file
const url = URL.createObjectURL(outFile);
downloadLink.href = url;
Expand Down
17 changes: 14 additions & 3 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export class Niimath {
constructor() {
this.worker = null;
this.operators = operators;
this.outputDataType = 'float'; // Possible datatypes are: char short int float double input
this.dataTypes = {char: 'char', short: 'short', int: 'int', float: 'float', double: 'double', input: 'input'};
}

init() {
Expand All @@ -25,18 +27,27 @@ export class Niimath {
});
}

setOutputDataType(type) {
if (Object.values(this.dataTypes).includes(type)) {
this.outputDataType = type;
} else {
throw new Error(`Invalid data type: ${type}`);
}
}

image(file) {
return new ImageProcessor({ worker: this.worker, file, operators: this.operators });
return new ImageProcessor({ worker: this.worker, file, operators: this.operators, outputDataType: this.outputDataType });
}
}

class ImageProcessor {

constructor({ worker, file, operators }) {
constructor({ worker, file, operators, outputDataType }) {
this.worker = worker;
this.file = file;
this.operators = operators;
this.commands = [];
this.outputDataType = outputDataType ? outputDataType : 'float'; // default to float
this._generateMethods();
}

Expand Down Expand Up @@ -116,7 +127,7 @@ class ImageProcessor {
}
};

const args = [this.file.name, ...this.commands, outName];
const args = [this.file.name, ...this.commands, outName, '-odt', this.outputDataType];
if (this.worker === null) {
reject(new Error('Worker not initialized. Did you await the init() method?'));
}
Expand Down

0 comments on commit 3f8d03e

Please sign in to comment.