-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mesh-io): add typescript bindgen output
- Loading branch information
Showing
161 changed files
with
11,336 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,5 @@ | ||
node_modules | ||
.DS_Store | ||
test | ||
cypress | ||
demo-app |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { defineConfig } from 'vite' | ||
import { viteStaticCopy } from 'vite-plugin-static-copy' | ||
import path from 'path' | ||
|
||
export default defineConfig({ | ||
root: path.join('test', 'browser', 'demo-app'), | ||
build: { | ||
outDir: '../../../demo-app', | ||
emptyOutDir: true, | ||
}, | ||
worker: { | ||
format: 'es' | ||
}, | ||
optimizeDeps: { | ||
exclude: ['itk-wasm', '@itk-wasm/image-io'] | ||
}, | ||
plugins: [ | ||
// put lazy loaded JavaScript and Wasm bundles in dist directory | ||
viteStaticCopy({ | ||
targets: [ | ||
{ src: '../../../dist/pipelines/*', dest: 'pipelines' }, | ||
{ src: '../../../node_modules/@itk-wasm/image-io/dist/pipelines/*.{js,wasm,wasm.zst}', dest: 'pipelines' }, | ||
], | ||
}) | ||
], | ||
}) |
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,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>@itk-wasm/mesh-io</title> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | ||
<meta name="description" content="Input and output for scientific and medical image file formats."> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> | ||
<link rel="stylesheet" media="(prefers-color-scheme: dark)" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css"> | ||
<link rel="stylesheet" media="(prefers-color-scheme: light)" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css"> | ||
<style> | ||
:root { | ||
--base-font-size: 16px; | ||
--theme-color : lightblue; | ||
--code-theme-text : #afcf7f; | ||
--code-font-weight : 750; | ||
--code-inline-background: hsl(var(--mono-hue), var(--mono-saturation), 35%); | ||
--mono-hue : 213; | ||
--mono-saturation : 0%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="app">Loading...</div> | ||
<script> | ||
window.$docsify = { | ||
logo: 'test/browser/demo-app/logo.svg', | ||
name: '@itk-wasm/mesh-io', | ||
repo: '' | ||
} | ||
</script> | ||
<!-- Docsify v4 --> | ||
<script src="https://cdn.jsdelivr.net/npm/docsify@4"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/docsify-copy-code/dist/docsify-copy-code.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-typescript.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-c.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-cpp.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-python.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/js/docsify-themeable.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/plugins/search.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/plugins/zoom-image.min.js"></script> | ||
</body> | ||
</html> |
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,51 @@ | ||
{ | ||
"name": "@itk-wasm/mesh-io", | ||
"version": "0.1.0", | ||
"description": "Input and output for scientific and medical image file formats.", | ||
"type": "module", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"browser": "./dist/index.js", | ||
"node": "./dist/index-node.js", | ||
"default": "./dist/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"start": "npm run copyShoelaceAssets && vite -c build/vite.config.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"build": "npm run build:tsc && npm run build:browser:workerEmbedded && npm run build:browser:workerEmbeddedMin && npm run build:demo", | ||
"build:browser:workerEmbedded": "esbuild --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.js ./src/index-worker-embedded.ts", | ||
"build:browser:workerEmbeddedMin": "esbuild --minify --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.min.js ./src/index-worker-embedded.min.ts", | ||
"build:tsc": "tsc --pretty", | ||
"copyShoelaceAssets": "shx mkdir -p test/browser/demo-app/public && shx cp -r node_modules/@shoelace-style/shoelace/dist/assets test/browser/demo-app/public/", | ||
"build:demo": "npm run copyShoelaceAssets && vite -c build/vite.config.js build" | ||
}, | ||
"keywords": [ | ||
"itk", | ||
"wasm", | ||
"webassembly", | ||
"wasi" | ||
], | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"itk-wasm": "^1.0.0-b.154" | ||
}, | ||
"devDependencies": { | ||
"@itk-wasm/image-io": "^0.2.0", | ||
"@shoelace-style/shoelace": "^2.5.2", | ||
"@types/node": "^20.2.5", | ||
"esbuild": "^0.19.5", | ||
"shx": "^0.3.4", | ||
"typescript": "^5.0.4", | ||
"vite": "^4.5.0", | ||
"vite-plugin-static-copy": "^0.17.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/InsightSoftwareConsortium/itk-wasm" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/mesh-io/typescript/src/byu-read-mesh-node-result.ts
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,14 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { JsonCompatible, Mesh } from 'itk-wasm' | ||
|
||
interface ByuReadMeshNodeResult { | ||
/** Whether the input could be read. If false, the output mesh is not valid. */ | ||
couldRead: JsonCompatible | ||
|
||
/** Output mesh */ | ||
mesh: Mesh | ||
|
||
} | ||
|
||
export default ByuReadMeshNodeResult |
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,78 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { | ||
JsonCompatible, | ||
Mesh, | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
runPipelineNode | ||
} from 'itk-wasm' | ||
|
||
import ByuReadMeshOptions from './byu-read-mesh-options.js' | ||
import ByuReadMeshNodeResult from './byu-read-mesh-node-result.js' | ||
|
||
import path from 'path' | ||
|
||
/** | ||
* Read a mesh file format and convert it to the itk-wasm file format | ||
* | ||
* @param {string} serializedMesh - Input mesh serialized in the file format | ||
* @param {ByuReadMeshOptions} options - options object | ||
* | ||
* @returns {Promise<ByuReadMeshNodeResult>} - result object | ||
*/ | ||
async function byuReadMeshNode( | ||
serializedMesh: string, | ||
options: ByuReadMeshOptions = {} | ||
) : Promise<ByuReadMeshNodeResult> { | ||
|
||
const mountDirs: Set<string> = new Set() | ||
|
||
const desiredOutputs: Array<PipelineOutput> = [ | ||
{ type: InterfaceTypes.JsonCompatible }, | ||
{ type: InterfaceTypes.Mesh }, | ||
] | ||
|
||
mountDirs.add(path.dirname(serializedMesh as string)) | ||
const inputs: Array<PipelineInput> = [ | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
const serializedMeshName = serializedMesh | ||
args.push(serializedMeshName) | ||
mountDirs.add(path.dirname(serializedMeshName)) | ||
|
||
// Outputs | ||
const couldReadName = '0' | ||
args.push(couldReadName) | ||
|
||
const meshName = '1' | ||
args.push(meshName) | ||
|
||
// Options | ||
args.push('--memory-io') | ||
if (typeof options.informationOnly !== "undefined") { | ||
options.informationOnly && args.push('--information-only') | ||
} | ||
|
||
const pipelinePath = path.join(path.dirname(import.meta.url.substring(7)), 'pipelines', 'byu-read-mesh') | ||
|
||
const { | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipelineNode(pipelinePath, args, desiredOutputs, inputs, mountDirs) | ||
if (returnValue !== 0 && stderr !== "") { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
couldRead: outputs[0]?.data as JsonCompatible, | ||
mesh: outputs[1]?.data as Mesh, | ||
} | ||
return result | ||
} | ||
|
||
export default byuReadMeshNode |
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,9 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
interface ByuReadMeshOptions { | ||
/** Only read image metadata -- do not read pixel data. */ | ||
informationOnly?: boolean | ||
|
||
} | ||
|
||
export default ByuReadMeshOptions |
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,17 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { JsonCompatible, Mesh } from 'itk-wasm' | ||
|
||
interface ByuReadMeshResult { | ||
/** WebWorker used for computation */ | ||
webWorker: Worker | null | ||
|
||
/** Whether the input could be read. If false, the output mesh is not valid. */ | ||
couldRead: JsonCompatible | ||
|
||
/** Output mesh */ | ||
mesh: Mesh | ||
|
||
} | ||
|
||
export default ByuReadMeshResult |
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,85 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { | ||
BinaryFile, | ||
JsonCompatible, | ||
Mesh, | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
runPipeline | ||
} from 'itk-wasm' | ||
|
||
import ByuReadMeshOptions from './byu-read-mesh-options.js' | ||
import ByuReadMeshResult from './byu-read-mesh-result.js' | ||
|
||
import { getPipelinesBaseUrl } from './pipelines-base-url.js' | ||
import { getPipelineWorkerUrl } from './pipeline-worker-url.js' | ||
|
||
/** | ||
* Read a mesh file format and convert it to the itk-wasm file format | ||
* | ||
* @param {File | BinaryFile} serializedMesh - Input mesh serialized in the file format | ||
* @param {ByuReadMeshOptions} options - options object | ||
* | ||
* @returns {Promise<ByuReadMeshResult>} - result object | ||
*/ | ||
async function byuReadMesh( | ||
webWorker: null | Worker | boolean, | ||
serializedMesh: File | BinaryFile, | ||
options: ByuReadMeshOptions = {} | ||
) : Promise<ByuReadMeshResult> { | ||
|
||
const desiredOutputs: Array<PipelineOutput> = [ | ||
{ type: InterfaceTypes.JsonCompatible }, | ||
{ type: InterfaceTypes.Mesh }, | ||
] | ||
|
||
let serializedMeshFile = serializedMesh | ||
if (serializedMesh instanceof File) { | ||
const serializedMeshBuffer = await serializedMesh.arrayBuffer() | ||
serializedMeshFile = { path: serializedMesh.name, data: new Uint8Array(serializedMeshBuffer) } | ||
} | ||
const inputs: Array<PipelineInput> = [ | ||
{ type: InterfaceTypes.BinaryFile, data: serializedMeshFile as BinaryFile }, | ||
] | ||
|
||
const args = [] | ||
// Inputs | ||
const serializedMeshName = (serializedMeshFile as BinaryFile).path | ||
args.push(serializedMeshName) | ||
|
||
// Outputs | ||
const couldReadName = '0' | ||
args.push(couldReadName) | ||
|
||
const meshName = '1' | ||
args.push(meshName) | ||
|
||
// Options | ||
args.push('--memory-io') | ||
if (typeof options.informationOnly !== "undefined") { | ||
options.informationOnly && args.push('--information-only') | ||
} | ||
|
||
const pipelinePath = 'byu-read-mesh' | ||
|
||
const { | ||
webWorker: usedWebWorker, | ||
returnValue, | ||
stderr, | ||
outputs | ||
} = await runPipeline(webWorker, pipelinePath, args, desiredOutputs, inputs, { pipelineBaseUrl: getPipelinesBaseUrl(), pipelineWorkerUrl: getPipelineWorkerUrl() }) | ||
if (returnValue !== 0 && stderr !== "") { | ||
throw new Error(stderr) | ||
} | ||
|
||
const result = { | ||
webWorker: usedWebWorker as Worker, | ||
couldRead: outputs[0]?.data as JsonCompatible, | ||
mesh: outputs[1]?.data as Mesh, | ||
} | ||
return result | ||
} | ||
|
||
export default byuReadMesh |
12 changes: 12 additions & 0 deletions
12
packages/mesh-io/typescript/src/byu-write-mesh-node-result.ts
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,12 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { JsonCompatible } from 'itk-wasm' | ||
|
||
interface ByuWriteMeshNodeResult { | ||
/** Whether the input could be written. If false, the output mesh is not valid. */ | ||
couldWrite: JsonCompatible | ||
|
||
/** Output mesh */ | ||
} | ||
|
||
export default ByuWriteMeshNodeResult |
Oops, something went wrong.