Skip to content

emscripten transform output array #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/python/itkwasm/itkwasm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""itkwasm: Python interface to itk-wasm WebAssembly modules."""

__version__ = "1.0b191"
__version__ = "1.0b192"

from .interface_types import InterfaceTypes
from .image import Image, ImageType, ImageRegion
Expand Down
2 changes: 1 addition & 1 deletion packages/core/python/itkwasm/itkwasm/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def run(
data_ptr = ri.get_output_array_address(0, index, idx * 2)
data_size = ri.get_output_array_size(0, index, idx * 2)
transform.fixedParameters = buffer_to_numpy_array(
transform.transformType.parametersValueType,
FloatTypes.Float64,
ri.wasmtime_lift(data_ptr, data_size),
)
if transform.numberOfParameters > 0:
Expand Down
2 changes: 1 addition & 1 deletion packages/core/python/itkwasm/test/test_pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pytest_pyodide import run_in_pyodide, copy_files_to_pyodide

#from itkwasm import __version__ as test_package_version
test_package_version = '1.0b191'
test_package_version = '1.0b192'


def package_wheel():
Expand Down
126 changes: 71 additions & 55 deletions packages/core/typescript/demo-app/src/utilities.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,109 @@
import * as itk from 'itk-wasm'
globalThis.itk = itk
import * as itk from "itk-wasm";
globalThis.itk = itk;

function downloadFile(content, filename) {
const url = URL.createObjectURL(new Blob([content]))
const a = document.createElement('a')
a.href = url
a.download = filename || 'download'
document.body.appendChild(a)
// Handle shared ArrayBuffers by creating a copy
let blobContent = content;
if (content instanceof ArrayBuffer || ArrayBuffer.isView(content)) {
// Create a copy to avoid shared ArrayBuffer issues
const buffer = content instanceof ArrayBuffer ? content : content.buffer;
const copy = new ArrayBuffer(buffer.byteLength);
new Uint8Array(copy).set(new Uint8Array(buffer));
blobContent = copy;
}

const url = URL.createObjectURL(new Blob([blobContent]));
const a = document.createElement("a");
a.href = url;
a.download = filename || "download";
document.body.appendChild(a);
function clickHandler(event) {
setTimeout(() => {
URL.revokeObjectURL(url)
a.removeEventListener('click', clickHandler)
}, 200)
};
a.addEventListener('click', clickHandler, false)
a.click()
return a
URL.revokeObjectURL(url);
a.removeEventListener("click", clickHandler);
}, 200);
}
a.addEventListener("click", clickHandler, false);
a.click();
return a;
}
globalThis.downloadFile = downloadFile
globalThis.downloadFile = downloadFile;

function interfaceTypeJsonReplacer (key, value) {
function interfaceTypeJsonReplacer(key, value) {
if (!!value && value.byteLength !== undefined) {
return String(value.slice(0, 6)) + '...'
return String(value.slice(0, 6)) + "...";
}
return value
return value;
}
globalThis.interfaceTypeJsonReplacer = interfaceTypeJsonReplacer
globalThis.interfaceTypeJsonReplacer = interfaceTypeJsonReplacer;

function escapeHtml(html) {
const div = document.createElement('div');
const div = document.createElement("div");
div.textContent = html;
const escaped = div.innerHTML;
div.remove()
return escaped
div.remove();
return escaped;
}
globalThis.escapeHtml = escapeHtml
globalThis.escapeHtml = escapeHtml;

function notify(title, message, variant = 'primary', icon = 'info-circle', duration = 3000) {
const slAlert = Object.assign(document.createElement('sl-alert'), {
function notify(
title,
message,
variant = "primary",
icon = "info-circle",
duration = 3000
) {
const slAlert = Object.assign(document.createElement("sl-alert"), {
variant,
closable: true,
duration: duration,
innerHTML: `
<sl-icon name="${icon}" slot="icon"></sl-icon>
<strong>${escapeHtml(title)}</strong><br />
${escapeHtml(message)}
`
`,
});

document.body.append(slAlert);
setTimeout(() => slAlert.toast(), 300)
setTimeout(() => slAlert.toast(), 300);
}
globalThis.notify = notify
globalThis.notify = notify;

function disableInputs(inputId) {
document.querySelectorAll(`#${inputId} sl-button`).forEach(button => {
button.disabled = true
})
document.querySelector(`#${inputId} sl-button[name="run"]`).loading = true
document.querySelectorAll(`#${inputId} sl-checkbox`).forEach(checkbox => {
checkbox.disabled = true
})
document.querySelectorAll(`#${inputId} sl-input`).forEach(input => {
input.disabled = true
})
document.querySelectorAll(`#${inputId} sl-button`).forEach((button) => {
button.disabled = true;
});
document.querySelector(`#${inputId} sl-button[name="run"]`).loading = true;
document.querySelectorAll(`#${inputId} sl-checkbox`).forEach((checkbox) => {
checkbox.disabled = true;
});
document.querySelectorAll(`#${inputId} sl-input`).forEach((input) => {
input.disabled = true;
});
}
globalThis.disableInputs = disableInputs
globalThis.disableInputs = disableInputs;

function enableInputs(inputId) {
document.querySelectorAll(`#${inputId} sl-button`).forEach(button => {
button.disabled = false
})
document.querySelector(`#${inputId} sl-button[name="run"]`).loading = false
document.querySelectorAll(`#${inputId} sl-checkbox`).forEach(checkbox => {
checkbox.disabled = false
})
document.querySelectorAll(`#${inputId} sl-input`).forEach(input => {
input.disabled = false
})
document.querySelectorAll(`#${inputId} sl-button`).forEach((button) => {
button.disabled = false;
});
document.querySelector(`#${inputId} sl-button[name="run"]`).loading = false;
document.querySelectorAll(`#${inputId} sl-checkbox`).forEach((checkbox) => {
checkbox.disabled = false;
});
document.querySelectorAll(`#${inputId} sl-input`).forEach((input) => {
input.disabled = false;
});
}
globalThis.enableInputs = enableInputs
globalThis.enableInputs = enableInputs;

function applyInputParsedJson(inputElement, modelMap, parameterName) {
try {
const parsedJson = JSON.parse(inputElement.value)
modelMap.set(parameterName, parsedJson)
inputElement.setCustomValidity('')
const parsedJson = JSON.parse(inputElement.value);
modelMap.set(parameterName, parsedJson);
inputElement.setCustomValidity("");
} catch (error) {
inputElement.setCustomValidity(error.message)
inputElement.setCustomValidity(error.message);
}
}
globalThis.applyInputParsedJson = applyInputParsedJson
globalThis.applyInputParsedJson = applyInputParsedJson;
2 changes: 1 addition & 1 deletion packages/core/typescript/itk-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itk-wasm",
"version": "1.0.0-b.188",
"version": "1.0.0-b.192",
"description": "High-performance spatial analysis in a web browser, Node.js, and reproducible execution across programming languages and hardware architectures.",
"type": "module",
"module": "./dist/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"itk-wasm": "1.0.0-b.188"
"itk-wasm": "1.0.0-b.192"
},
"devDependencies": {
"@itk-wasm/demo-app": "^0.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,10 +666,10 @@ function runPipelineEmscripten (
pipelineModule,
index,
transformIndex * 2,
transform.transformType.parametersValueType
FloatTypes.Float64
) as TypedArray
}
if (transform.numberOfFixedParameters > 0) {
if (transform.numberOfParameters > 0) {
transformList[transformIndex].parameters =
getPipelineModuleOutputArray(
pipelineModule,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/typescript/itk-wasm/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const version = '1.0.0-b.188'
const version = '1.0.0-b.192'

export default version
Loading
Loading