-
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): read-mesh and write-mesh
- Loading branch information
Showing
25 changed files
with
2,116 additions
and
24 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
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,9 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
defaultCommandTimeout: 40000, | ||
setupNodeEvents(on, config) { | ||
}, | ||
}, | ||
}); |
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,13 @@ | ||
export const demoServer = 'http://localhost:5173' | ||
|
||
import { IntTypes, FloatTypes, PixelTypes } from 'itk-wasm' | ||
|
||
export function verifyMesh (mesh) { | ||
cy.expect(mesh.meshType.dimension).to.equal(3) | ||
cy.expect(mesh.meshType.pointComponentType).to.equal(FloatTypes.Float32) | ||
cy.expect(mesh.meshType.cellComponentType).to.equal(IntTypes.UInt32) | ||
cy.expect(mesh.meshType.pointPixelType).to.equal(PixelTypes.Scalar) | ||
cy.expect(mesh.meshType.cellPixelType).to.equal(PixelTypes.Scalar) | ||
cy.expect(mesh.numberOfPoints).to.equal(2903) | ||
cy.expect(mesh.numberOfCells).to.equal(3263) | ||
} |
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 { demoServer, verifyMesh } from './common.ts' | ||
|
||
describe('read-mesh', () => { | ||
beforeEach(function() { | ||
cy.visit(demoServer) | ||
|
||
const testPathPrefix = '../test/data/input/' | ||
|
||
const testImageFiles = [ | ||
'cow.vtk' | ||
] | ||
testImageFiles.forEach((fileName) => { | ||
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName) | ||
}) | ||
}) | ||
|
||
it('Reads an mesh File in the demo', function () { | ||
cy.get('sl-tab[panel="readMesh-panel"]').click() | ||
|
||
const testFile = { contents: new Uint8Array(this['cow.vtk']), fileName: 'cow.vtk' } | ||
cy.get('#readMeshInputs input[name="serialized-mesh-file"]').selectFile([testFile,], { force: true }) | ||
cy.get('#readMesh-serialized-mesh-details').should('contain', '35,32') | ||
|
||
cy.get('#readMeshInputs sl-button[name="run"]').click() | ||
|
||
cy.get('#readMesh-mesh-details').should('contain', 'meshType') | ||
}) | ||
|
||
it('Reads an mesh BinaryFile', function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this['cow.vtk']).buffer | ||
const { mesh, webWorker } = await win.meshIo.readMesh(null, { data: new Uint8Array(arrayBuffer), path: 'cow.vtk' }) | ||
webWorker.terminate() | ||
verifyMesh(mesh) | ||
}) | ||
}) | ||
|
||
it('Reads an mesh File', function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this['cow.vtk']).buffer | ||
const cowFile = new win.File([arrayBuffer], 'cow.vtk') | ||
const { mesh, webWorker } = await win.meshIo.readMesh(null, cowFile) | ||
webWorker.terminate() | ||
verifyMesh(mesh) | ||
}) | ||
}) | ||
|
||
it('Reads re-uses a WebWorker', function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this['cow.vtk']).buffer | ||
const cowFile = new win.File([arrayBuffer], 'cow.vtk') | ||
const { webWorker } = await win.meshIo.readMesh(null, cowFile) | ||
const { mesh } = await win.meshIo.readMesh(webWorker, cowFile) | ||
webWorker.terminate() | ||
verifyMesh(mesh) | ||
}) | ||
}) | ||
|
||
it('Throws a catchable error for an invalid file', { defaultCommandTimeout: 120000 }, function () { | ||
cy.window().then(async (win) => { | ||
const invalidArray = new Uint8Array([21, 4, 4, 4, 4, 9, 5, 0, 82, 42]) | ||
const invalidBlob = new win.Blob([invalidArray]) | ||
const invalidFile = new win.File([invalidBlob], 'invalid.file') | ||
try { | ||
const { webWorker, mesh } = await win.meshIo.readMesh(null, invalidFile) | ||
webWorker.terminate() | ||
} catch (error) { | ||
cy.expect(error.message).to.equal('Could not find IO for: invalid.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,40 @@ | ||
import { demoServer, verifyMesh } from './common.ts' | ||
|
||
describe('write-mesh', () => { | ||
beforeEach(function() { | ||
cy.visit(demoServer) | ||
|
||
const testPathPrefix = '../test/data/input/' | ||
|
||
const testImageFiles = [ | ||
'cow.iwm.cbor' | ||
] | ||
testImageFiles.forEach((fileName) => { | ||
cy.readFile(`${testPathPrefix}${fileName}`, null).as(fileName) | ||
}) | ||
}) | ||
|
||
it('Writes an mesh in the demo', function () { | ||
cy.get('sl-tab[panel="writeMesh-panel"]').click() | ||
|
||
const testFile = { contents: new Uint8Array(this['cow.iwm.cbor']), fileName: 'cow.iwm.cbor' } | ||
cy.get('#writeMeshInputs input[name="mesh-file"]').selectFile([testFile,], { force: true }) | ||
cy.get('#writeMesh-mesh-details').should('contain', 'meshType') | ||
cy.get('#writeMeshInputs sl-input[name="serialized-mesh"]').find('input', { includeShadowDom: true }).type('cow.vtk', { force: true }) | ||
|
||
cy.get('#writeMeshInputs sl-button[name="run"]').click() | ||
|
||
cy.get('#writeMesh-serialized-mesh-details').should('contain', '35,32') | ||
}) | ||
|
||
it('Writes an mesh to an ArrayBuffer', function () { | ||
cy.window().then(async (win) => { | ||
const arrayBuffer = new Uint8Array(this['cow.iwm.cbor']).buffer | ||
const { mesh, webWorker } = await win.meshIo.readMesh(null, { data: new Uint8Array(arrayBuffer), path: 'cow.iwm.cbor' }) | ||
const { serializedMesh } = await win.meshIo.writeMesh(webWorker, mesh, 'cow.vtk') | ||
const { mesh: meshBack } = await win.meshIo.readMesh(webWorker, serializedMesh) | ||
webWorker.terminate() | ||
verifyMesh(meshBack) | ||
}) | ||
}) | ||
}) |
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,37 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************** | ||
// This example commands.ts shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) | ||
// | ||
// declare global { | ||
// namespace Cypress { | ||
// interface Chainable { | ||
// login(email: string, password: string): Chainable<void> | ||
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element> | ||
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element> | ||
// } | ||
// } | ||
// } |
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,31 @@ | ||
// *********************************************************** | ||
// This example support/e2e.ts is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
|
||
Cypress.on('uncaught:exception', (err, runnable) => { | ||
// we expect a 3rd party library error with message 'list not defined' | ||
// and don't want to fail the test so we return false | ||
if (err.message.includes('ResizeObserver loop completed with undelivered notifications')) { | ||
return false | ||
} | ||
// we still want to ensure there are no other unexpected | ||
// errors, so we let them fail the test | ||
}) | ||
|
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 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": [ | ||
"**/*.ts" | ||
], | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"sourceMap": false, | ||
"inlineSourceMap": true, | ||
"types": ["cypress"] | ||
}, | ||
} |
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
Oops, something went wrong.