-
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.
- Loading branch information
Showing
22 changed files
with
679 additions
and
32 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import vtkPolyDataReadMeshNode from './vtk-poly-data-read-mesh-node.js' | ||
import vtkPolyDataWriteMeshNode from './vtk-poly-data-write-mesh-node.js' | ||
import objReadMeshNode from './obj-read-mesh-node.js' | ||
import objWriteMeshNode from './obj-write-mesh-node.js' | ||
import stlReadMeshNode from './stl-read-mesh-node.js' | ||
import stlWriteMeshNode from './stl-write-mesh-node.js' | ||
import offReadMeshNode from './off-read-mesh-node.js' | ||
import offWriteMeshNode from './off-write-mesh-node.js' | ||
import wasmReadMeshNode from './wasm-read-mesh-node.js' | ||
import wasmWriteMeshNode from './wasm-write-mesh-node.js' | ||
import wasmZstdReadMeshNode from './wasm-zstd-read-mesh-node.js' | ||
import wasmZstdWriteMeshNode from './wasm-zstd-write-mesh-node.js' | ||
import swcReadMeshNode from './swc-read-mesh-node.js' | ||
import swcWriteMeshNode from './swc-write-mesh-node.js' | ||
import byuReadMeshNode from './byu-read-mesh-node.js' | ||
import byuWriteMeshNode from './byu-write-mesh-node.js' | ||
import freeSurferAsciiReadMeshNode from './free-surfer-ascii-read-mesh-node.js' | ||
import freeSurferAsciiWriteMeshNode from './free-surfer-ascii-write-mesh-node.js' | ||
import freeSurferBinaryReadMeshNode from './free-surfer-binary-read-mesh-node.js' | ||
import freeSurferBinaryWriteMeshNode from './free-surfer-binary-write-mesh-node.js' | ||
|
||
const meshIoIndexNode = new Map([ | ||
['vtk', [vtkPolyDataReadMeshNode, vtkPolyDataWriteMeshNode]], | ||
['obj', [objReadMeshNode, objWriteMeshNode]], | ||
['stl', [stlReadMeshNode, stlWriteMeshNode]], | ||
['off', [offReadMeshNode, offWriteMeshNode]], | ||
['wasm', [wasmReadMeshNode, wasmWriteMeshNode]], | ||
['wasm-zst', [wasmZstdReadMeshNode, wasmZstdWriteMeshNode]], | ||
['swc', [swcReadMeshNode, swcWriteMeshNode]], | ||
['byu', [byuReadMeshNode, byuWriteMeshNode]], | ||
['free-surfer-ascii', [freeSurferAsciiReadMeshNode, freeSurferAsciiWriteMeshNode]], | ||
['free-surfer-binary', [freeSurferBinaryReadMeshNode, freeSurferBinaryWriteMeshNode]], | ||
]) | ||
|
||
export default meshIoIndexNode |
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,72 @@ | ||
import path from 'path' | ||
import mime from 'mime-types' | ||
|
||
import { | ||
Mesh, | ||
getFileExtension, | ||
} from 'itk-wasm' | ||
|
||
import mimeToMeshIo from './mime-to-mesh-io.js' | ||
import extensionToMeshIo from './extension-to-mesh-io.js' | ||
import meshIoIndexNode from './mesh-io-index-node.js' | ||
|
||
import ReadMeshOptions from './read-mesh-options.js' | ||
|
||
interface ReaderResult { | ||
couldRead: boolean, | ||
mesh: Mesh | ||
} | ||
interface ReaderOptions { | ||
/** Only read image metadata -- do not read pixel data. */ | ||
informationOnly?: boolean | ||
} | ||
type Reader = (serializedMesh: string, options: ReaderOptions) => Promise<ReaderResult> | ||
|
||
|
||
/** | ||
* Read a mesh file format and convert it to the itk-wasm file format | ||
* | ||
* @param {string} serializedMesh - Path to input mesh serialized in the file format | ||
* @param {ReadMeshOptions} options - options to cast resulting mesh type or to only read mesh metadata | ||
* | ||
* @returns {Promise<Mesh>} - Mesh result | ||
*/ | ||
async function readMeshNode( | ||
serializedMesh: string, | ||
options: ReadMeshOptions = {} | ||
) : Promise<Mesh> { | ||
|
||
const absoluteFilePath = path.resolve(serializedMesh) | ||
const mimeType = mime.lookup(absoluteFilePath) | ||
const extension = getFileExtension(absoluteFilePath) | ||
|
||
let io = null | ||
if (mimeType && mimeToMeshIo.has(mimeType)) { | ||
io = mimeToMeshIo.get(mimeType) | ||
} else if (extensionToMeshIo.has(extension)) { | ||
io = extensionToMeshIo.get(extension) | ||
} else { | ||
for (const readerWriter of meshIoIndexNode.values()) { | ||
if (readerWriter[0] !== null) { | ||
let { couldRead, mesh } = await (readerWriter[0] as Reader)(absoluteFilePath, { informationOnly: options.informationOnly }) | ||
if (couldRead) { | ||
return mesh | ||
} | ||
} | ||
} | ||
} | ||
if (io === null ) { | ||
throw Error('Could not find IO for: ' + absoluteFilePath) | ||
} | ||
const readerWriter = meshIoIndexNode.get(io as string) | ||
|
||
const reader = (readerWriter as Array<Reader>)[0] | ||
let { couldRead, mesh } = await reader(absoluteFilePath, { informationOnly: options.informationOnly }) | ||
if (!couldRead) { | ||
throw Error('Could not read: ' + absoluteFilePath) | ||
} | ||
|
||
return mesh | ||
} | ||
|
||
export default readMeshNode |
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,6 @@ | ||
interface ReadMeshOptions { | ||
/** Only read mesh metadata -- do not read pixel data. */ | ||
informationOnly?: boolean | ||
} | ||
|
||
export default ReadMeshOptions |
14 changes: 14 additions & 0 deletions
14
packages/mesh-io/typescript/src/wasm-zstd-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 WasmZstdReadMeshNodeResult { | ||
/** Whether the input could be read. If false, the output mesh is not valid. */ | ||
couldRead: JsonCompatible | ||
|
||
/** Output mesh */ | ||
mesh: Mesh | ||
|
||
} | ||
|
||
export default WasmZstdReadMeshNodeResult |
78 changes: 78 additions & 0 deletions
78
packages/mesh-io/typescript/src/wasm-zstd-read-mesh-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,78 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { | ||
JsonCompatible, | ||
Mesh, | ||
InterfaceTypes, | ||
PipelineOutput, | ||
PipelineInput, | ||
runPipelineNode | ||
} from 'itk-wasm' | ||
|
||
import WasmZstdReadMeshOptions from './wasm-zstd-read-mesh-options.js' | ||
import WasmZstdReadMeshNodeResult from './wasm-zstd-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 {WasmZstdReadMeshOptions} options - options object | ||
* | ||
* @returns {Promise<WasmZstdReadMeshNodeResult>} - result object | ||
*/ | ||
async function wasmZstdReadMeshNode( | ||
serializedMesh: string, | ||
options: WasmZstdReadMeshOptions = {} | ||
) : Promise<WasmZstdReadMeshNodeResult> { | ||
|
||
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', 'wasm-zstd-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 wasmZstdReadMeshNode |
9 changes: 9 additions & 0 deletions
9
packages/mesh-io/typescript/src/wasm-zstd-read-mesh-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,9 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
interface WasmZstdReadMeshOptions { | ||
/** Only read image metadata -- do not read pixel data. */ | ||
informationOnly?: boolean | ||
|
||
} | ||
|
||
export default WasmZstdReadMeshOptions |
17 changes: 17 additions & 0 deletions
17
packages/mesh-io/typescript/src/wasm-zstd-read-mesh-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,17 @@ | ||
// Generated file. To retain edits, remove this comment. | ||
|
||
import { JsonCompatible, Mesh } from 'itk-wasm' | ||
|
||
interface WasmZstdReadMeshResult { | ||
/** 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 WasmZstdReadMeshResult |
Oops, something went wrong.