Skip to content

Commit 1fea666

Browse files
committed
feat(WebpackExample): Add mesh reading support
1 parent fc0dacf commit 1fea666

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

examples/Webpack/dist/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ textarea {
88
position: absolute;
99
box-sizing: border-box;
1010
width: 100%;
11+
height: 80%;
1112
bottom: 0px;
1213
left: 0px;
1314
top: 50px;

examples/Webpack/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/Webpack/src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
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
outputTextArea.textContent = "Loading...";
66
const dataTransfer = event.dataTransfer
77
const files = event.target.files || dataTransfer.files
8-
return readImageFile(null, files[0])
9-
.then(function ({ image, webWorker }) {
8+
return readFile(null, files[0])
9+
.then(function ({ image, mesh, webWorker }) {
1010
webWorker.terminate()
11+
const imageOrMesh = image || mesh
12+
1113
function replacer (key, value) {
1214
if (!!value && value.byteLength !== undefined) {
1315
return String(value.slice(0, 6)) + '...'
1416
}
1517
return value
1618
}
17-
outputTextArea.textContent = JSON.stringify(image, replacer, 4)
19+
outputTextArea.textContent = JSON.stringify(imageOrMesh, replacer, 4)
1820
})
1921
})
2022

examples/Webpack/test/index.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios from 'axios'
33

44
import { outputFileInformation } from '../src/index'
55

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

0 commit comments

Comments
 (0)