Skip to content

Commit fc0dacf

Browse files
committed
feat(UnpkgIOExample): Add support for reading meshes
1 parent 778fd3e commit fc0dacf

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

examples/UnpkgIO/dist/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5+
<link rel="stylesheet" href="styles.css">
56
</head>
67
<body>
78
<div>

examples/UnpkgIO/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"dependencies": {
2727
"curry": "^1.2.0",
2828
"expose-loader": "^0.7.5",
29-
"itk": "^9.2.0"
29+
"itk": "^9.5.0"
3030
},
3131
"devDependencies": {
3232
"@babel/core": "^7.2.0",

examples/UnpkgIO/src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import readImageFile from 'itk/readImageFile'
1+
import readFile from 'itk/readFile'
22
import curry from 'curry'
33

44
const outputFileInformation = curry(function outputFileInformation (outputTextArea, event) {
55
const dataTransfer = event.dataTransfer
66
const files = event.target.files || dataTransfer.files
7-
return readImageFile(null, files[0])
8-
.then(function ({ image, webWorker }) {
7+
return readFile(null, files[0])
8+
.then(function ({ image, mesh, webWorker }) {
99
webWorker.terminate()
10+
const imageOrMesh = image || mesh
11+
1012
function replacer (key, value) {
1113
if (!!value && value.byteLength !== undefined) {
1214
return String(value.slice(0, 6)) + '...'
1315
}
1416
return value
1517
}
16-
outputTextArea.textContent = JSON.stringify(image, replacer, 4)
18+
outputTextArea.textContent = JSON.stringify(imageOrMesh, replacer, 4)
1719
})
1820
})
1921

examples/UnpkgIO/test/index.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import config from './itkConfig'
66
import { outputFileInformation } from '../src/index'
77
console.log(config)
88

9-
test('Loading an image file and displaying its contents', (t) => {
9+
test('Load an image file and display its contents', (t) => {
1010
const expectedOutput = `{
1111
"imageType": {
1212
"dimension": 2,
@@ -49,8 +49,52 @@ test('Loading an image file and displaying its contents', (t) => {
4949
document.body.appendChild(outputTextArea)
5050
outputFileInformation(outputTextArea, event)
5151
.then(function () {
52+
outputTextArea.remove()
5253
t.equal(outputTextArea.textContent, expectedOutput)
5354
t.end()
5455
})
5556
})
5657
})
58+
59+
test('Load a mesh file and display its contents', (t) => {
60+
const expectedOutput = `{
61+
"meshType": {
62+
"dimension": 3,
63+
"pointComponentType": "float",
64+
"pointPixelComponentType": null,
65+
"pointPixelType": 1,
66+
"pointPixelComponents": 0,
67+
"cellComponentType": "uint32_t",
68+
"cellPixelComponentType": null,
69+
"cellPixelType": 1,
70+
"cellPixelComponents": 0
71+
},
72+
"name": "Mesh",
73+
"numberOfPoints": 2903,
74+
"points": "3.716360092163086,2.3433899879455566,0,4.126560211181641,0.6420270204544067,0...",
75+
"numberOfPointPixels": 0,
76+
"pointData": null,
77+
"numberOfCells": 3263,
78+
"cells": "4,4,250,251,210,252...",
79+
"numberOfCellPixels": 0,
80+
"cellData": null,
81+
"cellBufferSize": 18856,
82+
"numberofPointPixels": 0,
83+
"numberofCellPixels": 0
84+
}`
85+
const meshURL = 'https://data.kitware.com/api/v1/file/5c72abb18d777f072b610e69/download'
86+
return axios.get(meshURL, { responseType: 'blob' })
87+
.then((response) => {
88+
const testFile = new window.File([response.data], 'cow.vtk')
89+
// mock the event
90+
const event = { target: { files: [testFile] } }
91+
const outputTextArea = document.createElement('textarea')
92+
document.body.appendChild(outputTextArea)
93+
outputFileInformation(outputTextArea, event)
94+
.then(function () {
95+
outputTextArea.remove()
96+
t.equal(outputTextArea.textContent, expectedOutput, 'Text area matches expected output')
97+
t.end()
98+
})
99+
})
100+
})

0 commit comments

Comments
 (0)