-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transform-io): add writeTransformNode
And implement related fixes.
- Loading branch information
Showing
19 changed files
with
208 additions
and
49 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
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
Binary file modified
BIN
+1.43 KB
(100%)
...m-transform-io-wasi/itkwasm_transform_io_wasi/wasm_modules/hdf5-write-transform.wasi.wasm
Binary file not shown.
Binary file modified
BIN
+1.43 KB
(100%)
...sm-transform-io-wasi/itkwasm_transform_io_wasi/wasm_modules/mat-write-transform.wasi.wasm
Binary file not shown.
Binary file modified
BIN
+1.43 KB
(100%)
...sm-transform-io-wasi/itkwasm_transform_io_wasi/wasm_modules/mnc-write-transform.wasi.wasm
Binary file not shown.
Binary file modified
BIN
+1.43 KB
(100%)
...sm-transform-io-wasi/itkwasm_transform_io_wasi/wasm_modules/txt-write-transform.wasi.wasm
Binary file not shown.
Binary file modified
BIN
+1.44 KB
(100%)
...m-transform-io-wasi/itkwasm_transform_io_wasi/wasm_modules/wasm-write-transform.wasi.wasm
Binary file not shown.
Binary file modified
BIN
+1.44 KB
(100%)
...nsform-io-wasi/itkwasm_transform_io_wasi/wasm_modules/wasm-zstd-write-transform.wasi.wasm
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
export { default as version } from "./version.js"; | ||
export { default as version } from './version.js' | ||
|
||
export type { JsonCompatible } from "itk-wasm"; | ||
export type { TransformList } from "itk-wasm"; | ||
export type { JsonCompatible } from 'itk-wasm' | ||
export type { TransformList } from 'itk-wasm' |
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
82 changes: 82 additions & 0 deletions
82
packages/transform-io/typescript/src/write-transform-node.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,82 @@ | ||
import path from "path"; | ||
|
||
import { TransformList, getFileExtension } from "itk-wasm"; | ||
|
||
import mimeToTransformIo from "./mime-to-transform-io.js"; | ||
import extensionToTransformIo from "./extension-to-transform-io.js"; | ||
import transformIoIndexNode from "./transform-io-index-node.js"; | ||
|
||
import WriteTransformOptions from "./write-transform-options.js"; | ||
|
||
interface WriterOptions { | ||
useCompression?: boolean; | ||
floatParameters?: boolean; | ||
} | ||
interface WriterResult { | ||
couldWrite: boolean; | ||
} | ||
type Writer = ( | ||
transform: TransformList, | ||
serializedTransform: string, | ||
options: WriterOptions | ||
) => Promise<WriterResult>; | ||
|
||
/** | ||
* Write a transform to a serialized file format and from an the itk-wasm Transform | ||
* | ||
* @param {Transform} transform - Input transform | ||
* @param {string} serializedTransform - Output transform serialized in the file format. | ||
* @param {WriteTransformOptions} options - options object | ||
* | ||
* @returns {void} - result object | ||
*/ | ||
async function writeTransformNode( | ||
transform: TransformList, | ||
serializedTransform: string, | ||
options: WriteTransformOptions = {} | ||
): Promise<void> { | ||
const absoluteFilePath = path.resolve(serializedTransform); | ||
const mimeType = options.mimeType; | ||
const extension = getFileExtension(absoluteFilePath); | ||
|
||
let inputTransform = transform; | ||
|
||
let io = null; | ||
if (typeof mimeType !== "undefined" && mimeToTransformIo.has(mimeType)) { | ||
io = mimeToTransformIo.get(mimeType); | ||
} else if (extensionToTransformIo.has(extension)) { | ||
io = extensionToTransformIo.get(extension); | ||
} else { | ||
for (const readerWriter of transformIoIndexNode.values()) { | ||
if (readerWriter[1] !== null) { | ||
let { couldWrite } = await (readerWriter[1] as Writer)( | ||
inputTransform, | ||
absoluteFilePath, | ||
{ | ||
useCompression: options.useCompression, | ||
floatParameters: options.floatParameters, | ||
} | ||
); | ||
if (couldWrite) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
if (io === null) { | ||
throw Error("Could not find IO for: " + absoluteFilePath); | ||
} | ||
const readerWriter = transformIoIndexNode.get(io as string); | ||
|
||
const writer = (readerWriter as Array<Writer>)[1]; | ||
console.log("writer", writer); | ||
console.log("inputTransform", inputTransform); | ||
let { couldWrite } = await writer(inputTransform, absoluteFilePath, { | ||
useCompression: options.useCompression, | ||
}); | ||
if (!couldWrite) { | ||
throw Error("Could not write: " + absoluteFilePath); | ||
} | ||
} | ||
|
||
export default writeTransformNode; |
14 changes: 14 additions & 0 deletions
14
packages/transform-io/typescript/src/write-transform-options.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 @@ | ||
import { WorkerPoolFunctionOption } from "itk-wasm"; | ||
|
||
interface WriteTransformOptions extends WorkerPoolFunctionOption { | ||
/** Use compression when writing the mesh if the IO formt supports it. */ | ||
useCompression?: boolean; | ||
|
||
/** Use float for the parameter value type. The default is double. */ | ||
floatParameters?: boolean; | ||
|
||
/** Mime type of the output mesh file. */ | ||
mimeType?: string; | ||
} | ||
|
||
export default WriteTransformOptions; |
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
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
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